Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Created April 19, 2022 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/1f6706c445fab4ad8a6fe51e4dd56cc3 to your computer and use it in GitHub Desktop.
Save mhkeller/1f6706c445fab4ad8a6fe51e4dd56cc3 to your computer and use it in GitHub Desktop.
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