You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a problem where pg creates String object whose length is incorrect.
Steps to reproduce
pg version 1.3.1
PostgreSQL version 12.6
Prepare a table named "test_records" with a VARCHAR column "name".
Insert a record with command INSERT INTO test_records VALUES ('日本語');
Run the following code (substitute ActiveRecord::Base.connection.raw_connection with your appropriate connection object)
to_sql='SELECT name FROM test_records'full_query="COPY (#{to_sql}) TO STDOUT"conn=ActiveRecord::Base.connection.raw_connectiondeco=PG::TextDecoder::CopyRow.newrows=[]conn.copy_data(full_query,deco)dowhile(row=conn.get_copy_data)dorows << rowendendtop=rows[0]p[top[0],top[0].length]
Expected Result
["日本語", 3]
is printed.
Actual Result
["日本語", 9]
is printed. 9 is actually size in bytes in UTF-8 encoding and not a number of characters.
The text was updated successfully, but these errors were encountered:
larskanis
added a commit
to larskanis/ruby-pg
that referenced
this issue
Feb 8, 2022
The COPY and record decoders use a ruby string as internal buffer.
If this buffer is given to the user, it must be passed through rb_str_modify().
Fixesged#427
Summary
I found a problem where pg creates String object whose length is incorrect.
Steps to reproduce
pg version 1.3.1
PostgreSQL version 12.6
INSERT INTO test_records VALUES ('日本語');
ActiveRecord::Base.connection.raw_connection
with your appropriate connection object)Expected Result
["日本語", 3]
is printed.
Actual Result
["日本語", 9]
is printed. 9 is actually size in bytes in UTF-8 encoding and not a number of characters.
The text was updated successfully, but these errors were encountered: