COPY (SELECT substring(uuid for 16) as r_keyid, * FROM openpgp_pubkey)
      TO '/tmp/openpgp_pubkey.csv'
      WITH (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *, ESCAPE '\');

COPY (SELECT * FROM openpgp_sig
      WHERE subkey_uuid IS NULL
      AND uid_uuid IS NULL
      AND uat_uuid IS NULL
      AND sig_uuid IS NULL)
      TO '/tmp/openpgp_sig_pubkey.csv'
      WITH (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *, ESCAPE '\');
COPY (SELECT * FROM openpgp_sig
      WHERE subkey_uuid IS NOT NULL)
      TO '/tmp/openpgp_sig_subkey.csv'
      WITH (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *, ESCAPE '\');
COPY (SELECT * FROM openpgp_sig
      WHERE uid_uuid IS NOT NULL)
      TO '/tmp/openpgp_sig_uid.csv'
      WITH (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *, ESCAPE '\');
COPY (SELECT * FROM openpgp_sig
      WHERE uat_uuid IS NOT NULL)
      TO '/tmp/openpgp_sig_uat.csv'
      WITH (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *, ESCAPE '\');

COPY (SELECT substring(uuid for 16) as r_keyid, * FROM openpgp_subkey)
      TO '/tmp/openpgp_subkey.csv'
      WITH (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *, ESCAPE '\');

COPY (SELECT * FROM openpgp_uat)
      TO '/tmp/openpgp_uat.csv'
      WITH (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *, ESCAPE '\');

COPY (SELECT * FROM openpgp_uid)
      TO '/tmp/openpgp_uid.csv'
      WITH (FORMAT CSV, HEADER TRUE, FORCE_QUOTE *, ESCAPE '\');
