Skip to content

Commit

Permalink
tree: return correct parse error for pg_lsn
Browse files Browse the repository at this point in the history
This patch changes the error returned upon failing to parse a PG_LSN
value to match postgres. Previously, the error was an internal error.

Informs cockroachdb#111327

Release note: None
  • Loading branch information
DrewKimball committed Oct 17, 2023
1 parent b8c9297 commit 5846580
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 19 additions & 6 deletions pkg/sql/logictest/testdata/logic_test/pg_lsn
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ SELECT 'A01F0/1AAA'::pg_lsn
----
A01F0/1AAA

statement error could not parse pg_lsn
SELECT 'A/G'::pg_lsn

statement error could not parse pg_lsn
SELECT '0G'::pg_lsn

statement ok
CREATE TABLE pg_lsn_table(id pg_lsn PRIMARY KEY, val pg_lsn)

Expand Down Expand Up @@ -80,3 +74,22 @@ SELECT * FROM ( VALUES
23021024706816
18446744073709551615
-18446744073709551615

statement error pgcode 22P02 pq: invalid input syntax for type pg_lsn: \"A/G\"
SELECT 'A/G'::pg_lsn

statement error pgcode 22P02 pq: invalid input syntax for type pg_lsn: \"0G\"
SELECT '0G'::pg_lsn

statement error pgcode 22P02 pq: invalid input syntax for type pg_lsn: \"ab\"
SELECT 'ab'::PG_LSN;

statement error pgcode 22P02 pq: pg_lsn\(\): invalid input syntax for type pg_lsn: \"ab\"
SELECT pg_lsn('ab');

statement error pgcode 22P02 pq: invalid input syntax for type pg_lsn: \"1\"
SELECT '1'::PG_LSN;

statement error pgcode 22P02 pq: invalid input syntax for type pg_lsn: \"\"
SELECT ''::PG_LSN;

4 changes: 3 additions & 1 deletion pkg/sql/sem/tree/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3629,7 +3629,9 @@ func NewDPGLSN(l lsn.LSN) *DPGLSN {
func ParseDPGLSN(str string) (*DPGLSN, error) {
v, err := lsn.ParseLSN(str)
if err != nil {
return nil, errors.Wrapf(err, "could not parse pg_lsn")
return nil, pgerror.Newf(pgcode.InvalidTextRepresentation,
"invalid input syntax for type pg_lsn: \"%s\"", str,
)
}
return NewDPGLSN(v), nil
}
Expand Down

0 comments on commit 5846580

Please sign in to comment.