Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: lib/pq confused by unicode characters in text[], while psql is OK with them #31872

Closed
dmkret opened this issue Oct 25, 2018 · 6 comments · Fixed by #66079
Closed

sql: lib/pq confused by unicode characters in text[], while psql is OK with them #31872

dmkret opened this issue Oct 25, 2018 · 6 comments · Fixed by #66079
Labels
A-sql-pgwire pgwire protocol issues. C-investigation Further steps needed to qualify. C-label will change. O-community Originated from the community

Comments

@dmkret
Copy link

dmkret commented Oct 25, 2018

russian character \u0422 'Т' (capital te) not saved well if it's inside of a string array.

To Reproduce

import "github.com/lib/pq"
...
rows, err := db.Query("SELECT ARRAY ['У, 'Л', 'Т']")
for rows.Next() {
    var value pq.StringArray
    rows.Scan(&value)
    fmt.Println(value)
}

output for cockroachdb> {"У", "Л" ,"\u0422"}
output for postgresql> {"У", "Л", "Т"}

Environment:

  • CockroachDB version: 2.0.6
  • Client app: cockroach sql, golang: pq

Add any other context about the problem here.

@knz
Copy link
Contributor

knz commented Oct 25, 2018

Thanks Anton for your problem report.
The problem is strictly in the Go driver lib/pq not in CockroachDB (note: cockroach sql also uses lib/pq and thus is affected equally by its bugs).

If you use the psql command from PostgreSQL and connect it to a CockroachDB server, you will see the right output:

kena@kenabook ~/cockroach % psql -U root -h localhost -p 26257
psql (10.5 (Ubuntu 10.5-0ubuntu0.18.04), server 9.5.0)
Type "help" for help.

root=# SELECT ARRAY ['У', 'Л', 'Т'];
     array
---------------
 {"У","Л","Т"}
(1 row)

Note also that we are aware of numerous problems with lib/pq. At this time we recommend using pgx instead, although the particular Unicode situation you are facing may not be handled by pgx either (you'd need to check)

@knz knz added O-community Originated from the community C-investigation Further steps needed to qualify. C-label will change. labels Oct 25, 2018
@knz knz added this to Triage in (DEPRECATED) SQL Front-end, Lang & Semantics via automation Oct 25, 2018
@knz knz changed the title sql: bad unicode character stored in text[] sql: lib/pq confused by unicode characters in text[], while psql is OK with them Oct 25, 2018
@knz knz added this to To do in DB Server & Security via automation Oct 25, 2018
@knz knz added the A-sql-pgwire pgwire protocol issues. label Oct 25, 2018
@knz knz moved this from Triage to Backlog in (DEPRECATED) SQL Front-end, Lang & Semantics Oct 25, 2018
@dmkret
Copy link
Author

dmkret commented Oct 25, 2018

@knz, thanks for reply!

I have the same issue with psql. Probably it is a store processing problem.

Reproduce

Create table with data

root@81142ab6c98d:/cockroach# ./cockroach sql --insecure           
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
#
# Server version: CockroachDB CCL v2.0.6 (x86_64-unknown-linux-gnu, built 2018/10/01 13:59:40, go1.10) (same version as client)
# Cluster ID: b60deba7-37ed-43f6-986f-b3e20e62ef54
#
# Enter \? for a brief introduction.
#
warning: no current database set. Use SET database = <dbname> to change, CREATE DATABASE to make a new database.
root@:26257/> create database test;
CREATE DATABASE

Time: 10.19165ms

root@:26257/> set database = test;
SET

Time: 295.408µs

root@:26257/test> create table test (test text[] NOT NULL);
CREATE TABLE

Time: 13.422543ms

root@:26257/test> insert into test values ('Т');
pq: value type string doesn't match type ARRAY of column "test"
root@:26257/test> insert into test values (ARRAY ['Т']);
INSERT 1

Time: 2.62925ms

root@:26257/test> select * from test;
+------------+
|    test    |
+------------+
| {"\u0422"} |
+------------+
(1 row)

Time: 3.549855ms

Select data using psql

root@81142ab6c98d:/cockroach# psql -h 127.0.0.1 -d test -p 26257
psql (9.4.19, server 9.5.0)
WARNING: psql major version 9.4, server major version 9.5.
         Some psql features might not work.
Type "help" for help.

test=> select * from test;
    test    
------------
 {"\u0422"}
(1 row)

Also I have the same issue with golang: pgx driver.

@knz
Copy link
Contributor

knz commented Oct 25, 2018

  1. That's something different, your previous example was using an array[] expression only and not storing anything in the table.

Nevertheless, you can verify that the issue is only in the client/server protocol and not in the CockroachDB store: select length(test[1]) from test should still return 1.

  1. The particular client/server protocol problem revealed in your test is a known limitation of CockroachDB 2.0 and has been fixed in the upcoming 2.1 release.

@dmkret
Copy link
Author

dmkret commented Oct 25, 2018

Yes select length(test[1]) from test returning 1.

root@:26257/test> select length(test[1]) from test;
+--------+
| length |
+--------+
|      1 |
+--------+
(1 row)

Time: 1.664317ms

@dmkret
Copy link
Author

dmkret commented Nov 1, 2018

Since CockroachDB version: 2.1.0 it's ok with lib/pq.

@knz
Copy link
Contributor

knz commented Nov 1, 2018

Thank you for confirming.

@mjibson btw this is an example of what we were discussing last week, encoding behavior is different but is valid.

@maddyblue maddyblue self-assigned this Nov 1, 2018
@piyush-singh piyush-singh moved this from To do to 2.2 Release in DB Server & Security Jan 15, 2019
@piyush-singh piyush-singh moved this from 19.2 Release to 19.1 in DB Server & Security Mar 6, 2019
@knz knz moved this from 19.1 to 19.2 Release in DB Server & Security Aug 2, 2019
@knz knz moved this from 19.2 Release to 20.1 in DB Server & Security Sep 24, 2019
@knz knz moved this from 20.1 stabilization to 20.2 draft in DB Server & Security Mar 19, 2020
@knz knz added this to To do in SQL CLI (demo + sql + workload + dump) via automation Apr 8, 2020
@knz knz removed this from 20.2 draft in DB Server & Security Apr 8, 2020
@craig craig bot closed this as completed in 97c4ad3 Jun 5, 2021
SQL CLI (demo + sql + workload + dump) automation moved this from To do to Done Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgwire pgwire protocol issues. C-investigation Further steps needed to qualify. C-label will change. O-community Originated from the community
Development

Successfully merging a pull request may close this issue.

3 participants