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: cast string to int[] or decimal[] when appropriate #41405

Closed
rafiss opened this issue Oct 7, 2019 · 1 comment · Fixed by #42704
Closed

sql: cast string to int[] or decimal[] when appropriate #41405

rafiss opened this issue Oct 7, 2019 · 1 comment · Fixed by #42704
Assignees
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) good first issue help wanted Help is requested / needed by the one who filed the issue to fix it.

Comments

@rafiss
Copy link
Collaborator

rafiss commented Oct 7, 2019

The following works in postgres, but not CockroachDB.

> create table arrtest (intarr int[], decarr decimal(2,1)[], strarr text[]);
CREATE TABLE

> INSERT INTO arrtest VALUES ('{1,2,3}','{3.1,1.4}', '{abc,f''a,"fa\"b",def}');
pq: value type string doesn't match type int[] of column "intarr"

Adding explicit casts makes it work.

> INSERT INTO arrtest VALUES ('{1,2,3}'::int[],'{3.1,1.4}'::decimal[], '{abc,f''a,"fa\"b",def}');
INSERT 1
@rafiss rafiss added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-pgcompat Semantic compatibility with PostgreSQL labels Oct 7, 2019
@jordanlewis
Copy link
Member

This should work via our constant upcast mechanism, which currently only automatically upcasts strings into string arrays. This should be a relatively straightforward addition.

See pkg/sql/sem/tree/constant.go, and notice how only StringArray is present in StrValAvailAllParsable.

@yuzefovich yuzefovich added the help wanted Help is requested / needed by the one who filed the issue to fix it. label Oct 12, 2019
@apantel apantel self-assigned this Nov 20, 2019
apantel added a commit to apantel/cockroach that referenced this issue Nov 22, 2019
Fixes cockroachdb#41405

Release note (sql change): Cast strign to int[] or decimal[] when appropriate
apantel added a commit to apantel/cockroach that referenced this issue Nov 25, 2019
Fixes cockroachdb#41405

Release note (sql change): Cast string to int[] or decimal[] when appropriate
craig bot pushed a commit that referenced this issue Nov 26, 2019
42601: storage/protectedts: introduce interfaces r=nvanbenschoten a=ajwerner

This commit introduces the interfaces for the protectedts subsystem.
The APIs are centered around protobufs for no great reason; it's mostly
an implementation vestige. I'm happy to swap it out for regular go structs.
That being said, there is something nice about having a well-defined encoding
for values.

This is the first of a number of PRs to come from #42600.

Release note: None

42704: Allow implicit casting to int[], decimal[] r=apantel a=apantel

Fixes #41405

Release note (sql change): Cast string to int[] or decimal[] when appropriate

42782: Correct some columns in pg_type from OID to REGPROC. r=apantel a=apantel

Fixes #42568

Release note (sql change): Some columns (typinput, typoutput,
typreceive, typsend, typmodin, typmodout, typanalyze) in pg_type were
incorrectly typed as OID instead of REGPROC.

42785: gceworker: fix substitution error r=RaduBerinde a=RaduBerinde

Some folks have been getting `${response,,}: bad substitution` errors,
I guess because their version of bash doesn't understand it. Changing
to a POSIX standard way to convert to lowercase.

Co-authored-by: Andrew Werner <[email protected]>
Co-authored-by: Adam Pantel <[email protected]>
Co-authored-by: Radu Berinde <[email protected]>
@craig craig bot closed this as completed in 9b16d51 Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) good first issue help wanted Help is requested / needed by the one who filed the issue to fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants