tembo-io / pg_later

Execute SQL now and get the results later.
PostgreSQL License
354 stars 10 forks source link

Can not execute query include single quote #52

Closed Shinglem closed 5 months ago

Shinglem commented 5 months ago

sql : select pglater.exec('select ''1''') as job_id; get error: [XX000] ERROR: Query parsing failed, please submit a valid query: ParserError("Expected end of statement, found: 1 at Line: 1, Column 10")

sql : select pglater.exec('select * from test_data where time >= ''2024-06-05 00:00:00 +0''') as job_id; get error: [XX000] ERROR: Query parsing failed, please submit a valid query: ParserError("Expected end of statement, found: 2024 at Line: 1, Column 41")

how do I execute these sql?

ChuckHend commented 5 months ago

Hi @Shinglem , would dollar-quoting instead of single quoting the values work for you?

select * from test_data;

            time            
----------------------------
 2024-06-05 12:23:48.282486
 2024-06-05 12:23:49.039151
 2024-06-05 12:23:49.6315
 2024-06-05 12:23:50.013119
(4 rows)
select pglater.exec('select * from test_data where time >= $$2024-06-05 00:00:00 +0$$') as job_id;  
 job_id 
--------
      5
(1 row)
postgres=# select jsonb_pretty(pglater.fetch_results(5));
                                   jsonb_pretty                                   
----------------------------------------------------------------------------------
 {                                                                               +
     "query": "select * from test_data where time >= $$2024-06-05 00:00:00 +0$$",+
     "job_id": 5,                                                                +
     "result": [                                                                 +
         {                                                                       +
             "time": "2024-06-05T12:23:48.282486"                                +
         },                                                                      +
         {                                                                       +
             "time": "2024-06-05T12:23:49.039151"                                +
         },                                                                      +
         {                                                                       +
             "time": "2024-06-05T12:23:49.6315"                                  +
         },                                                                      +
         {                                                                       +
             "time": "2024-06-05T12:23:50.013119"                                +
         }                                                                       +
     ],                                                                          +
     "status": "success"                                                         +
 }
(1 row)
Shinglem commented 5 months ago

it works.thanks.

ChuckHend commented 5 months ago

Awesome, going to close this issue. Thank you for asking!