Hacker News new | ask | show | jobs
by devrandomguy 3184 days ago
Or, we could just go all meta, in a Postgres shell:

  CREATE TABLE queries IF NOT EXISTS (
    name varchar(64),
    version varchar(64),
    query text,
    description text
  );

  NOTIFY chat 'Alice: Bob, please insert that query into the new queries table, and then NOTIFY "chat" with the name and version of it';
  LISTEN chat;

  Asynchronous notification "chat" with payload "Bob: See update-rank, v. borked-1" received from server process with PID 8448.
  Asynchronous notification "chat" with payload "Bob: I have it set to update in a temp table, so we don't have to reset the real table" received from server process with PID 8448.

  SELECT queries.query FROM queries WHERE name="update-rank" AND version="borked-1"
  INTO query;

  \echo query

  -- "Looks sane, let's run it"

  DO $$ EXECUTE query INTO result $$; -- Something like that, I'm guessing.

  \echo result
PL/PgSQL's EXECUTE is not to be confused with the EXECUTE that is used with stored procedures.

Bonus points if you edit the query by shelling out to sed or butterflies.