porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.54k stars 273 forks source link

CREATE OR REPLACE TRIGGER is valid syntax #971

Closed patrickReiis closed 4 weeks ago

patrickReiis commented 4 weeks ago

Hi, I don't know if I should create this issue here on in Kysely repo, anyways, I have this code that replaces an old TRIGGER:

  await sql`                                                                   
    CREATE OR REPLACE TRIGGER nostr_event_trigger                                                                                                                            
    AFTER INSERT OR UPDATE ON nostr_events                                        
    FOR EACH ROW EXECUTE FUNCTION notify_nostr_event()                            
  `.execute(db);  

According to Postgres docs, this is a valid syntax: https://www.postgresql.org/docs/14/sql-createtrigger.html

Full error log:

PostgresError: syntax error at or near "TRIGGER"
    at ErrorResponse (https://gitlab.com/soapbox-pub/postgres.js/-/raw/e79d7d2039446fbf7a37d4eca0d17e94a94b8b53/deno/src/connection.js:793:26)
    at handle (https://gitlab.com/soapbox-pub/postgres.js/-/raw/e79d7d2039446fbf7a37d4eca0d17e94a94b8b53/deno/src/connection.js:479:6)
    at data (https://gitlab.com/soapbox-pub/postgres.js/-/raw/e79d7d2039446fbf7a37d4eca0d17e94a94b8b53/deno/src/connection.js:318:9)
    at https://gitlab.com/soapbox-pub/postgres.js/-/raw/e79d7d2039446fbf7a37d4eca0d17e94a94b8b53/deno/polyfills.js:138:30
    at Array.forEach (<anonymous>)
    at call (https://gitlab.com/soapbox-pub/postgres.js/-/raw/e79d7d2039446fbf7a37d4eca0d17e94a94b8b53/deno/polyfills.js:138:16)
    at success (https://gitlab.com/soapbox-pub/postgres.js/-/raw/e79d7d2039446fbf7a37d4eca0d17e94a94b8b53/deno/polyfills.js:98:9)
    at eventLoopTick (ext:core/01_core.js:175:7) {
  name: "PostgresError",
  severity_local: "ERROR",
  severity: "ERROR",
  code: "42601",
  position: "24",
  file: "scan.l",
  line: "1145",
  routine: "scanner_yyerror"
}
porsager commented 4 weeks ago

Probably Kysely - works fine with raw Postgres.js ;)