Created
April 19, 2022 01:26
-
-
Save mhkeller/1f6706c445fab4ad8a6fe51e4dd56cc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Pool, Client } = require('pg'); | |
const namespaceQuery = `SELECT nspname | |
FROM pg_namespace | |
WHERE oid = pg_my_temp_schema();`; | |
const fnQuery = `CREATE OR REPLACE FUNCTION pg_temp.increment(i integer) | |
RETURNS integer | |
LANGUAGE plpgsql | |
AS $function$ | |
BEGIN | |
RETURN i + 1; | |
END; | |
$function$`; | |
async function main() { | |
const pool = new Pool() | |
const res0 = await pool.query(namespaceQuery); | |
console.log(res0); | |
const res1 = await pool.query(fnQuery); | |
console.log(res1); | |
const res2 = await pool.query(namespaceQuery); | |
console.log(res2); | |
const res3 = await pool.query(`SELECT pg_temp.increment(0)`); | |
console.log(res3); | |
try { | |
await pool.query('SELECT NWO()'); | |
} catch(err) { | |
} | |
const res4 = await pool.query(namespaceQuery); | |
console.log(res4); | |
const res5 = await pool.query(`SELECT pg_temp.increment(0)`); | |
console.log(res5); | |
await pool.end() | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment