-
Notifications
You must be signed in to change notification settings - Fork 185
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
pg_query could not detect length of RawStmt(s) with quoted characters #191
Comments
@valerysvl Thanks for the report! Could you clarify what you are expecting, and what you are seeing? From a quick test using pg_query, this appears to work correctly: irb(main):021:0> puts x
UPDATE _ScheduledJobs23816 SET _RestartAttemptNumber = CAST(0 AS NUMERIC), _State = CAST(1 AS NUMERIC), _StartTime = '2023-05-16 11:22:52'::timestamp, _FinishTime = '2023-05-16 11:21:27'::timestamp
WHERE _ScheduledJobs23816._ID = '\244\331\340\376\225\250\343\343A\005`Z3\270c\273'::bytea;
UPDATE _ScheduledJobs23816 SET _RestartAttemptNumber = CAST(0 AS NUMERIC), _State = CAST(1 AS NUMERIC), _StartTime = '2023-05-16 11:22:52'::timestamp, _FinishTime = '2023-05-16 11:21:27'::timestamp
WHERE _ScheduledJobs23816._ID = '\244\331\340\376\225\250\343\343A\005`Z3\270c\273'::bytea;
irb(main):015:0> PgQuery.parse(x).tree.stmts.map {|s| [s.stmt_location, s.stmt_len] }
=> [[0, 288], [289, 289]]
irb(main):018:0> x[..288]
=> "UPDATE _ScheduledJobs23816 SET _RestartAttemptNumber = CAST(0 AS NUMERIC), _State = CAST(1 AS NUMERIC), _StartTime = '2023-05-16 11:22:52'::timestamp, _FinishTime = '2023-05-16 11:21:27'::timestamp\nWHERE _ScheduledJobs23816._ID = '\\244\\331\\340\\376\\225\\250\\343\\343A\\005`Z3\\270c\\273'::bytea;"
irb(main):019:0> x[289..][..289]
=> "\nUPDATE _ScheduledJobs23816 SET _RestartAttemptNumber = CAST(0 AS NUMERIC), _State = CAST(1 AS NUMERIC), _StartTime = '2023-05-16 11:22:52'::timestamp, _FinishTime = '2023-05-16 11:21:27'::timestamp\nWHERE _ScheduledJobs23816._ID = '\\244\\331\\340\\376\\225\\250\\343\\343A\\005`Z3\\270c\\273'::bytea;" |
after parsing and following unpacking I am expecting stms_location as correct offset on source_query unpacked.stmts[0].stmt_len = 289; |
@valerysvl Its not clear to me what you mean with "correct offset on source_query" - from the data provided the len and location appear to be correct. Could you provide a fully self-contained example as a reproducer? |
Example query with 2 stataments:
UPDATE _ScheduledJobs23816 SET _RestartAttemptNumber = CAST(0 AS NUMERIC), _State = CAST(1 AS NUMERIC), _StartTime = '2023-05-16 11:22:52'::timestamp, _FinishTime = '2023-05-16 11:21:27'::timestamp
WHERE _ScheduledJobs23816._ID = '\244\331\340\376\225\250\343\343A\005
Z3\\270c\\273'::bytea; UPDATE _ScheduledJobs23816 SET _RestartAttemptNumber = CAST(0 AS NUMERIC), _State = CAST(1 AS NUMERIC), _StartTime = '2023-05-16 11:22:52'::timestamp, _FinishTime = '2023-05-16 11:21:27'::timestamp WHERE _ScheduledJobs23816._ID = '\\244\\331\\340\\376\\225\\250\\343\\343A\\005
Z3\270c\273'::bytea;pg_query can not detect on RawStmt list:
Used pg_query for PG15.1
The text was updated successfully, but these errors were encountered: