0
0

More than 1 year has passed since last update.

あるWebサービスの開発メモ・PostgreSQLチート

Last updated at Posted at 2022-08-19

品書き

reate or replace function get_suki_umu(user_id uuid)
returns table (ari bool)
language plpgsql
as $$
begin
  return query
  select exists (
    select 1 from comments
      where comments.user_id = get_suki_umu.user_id and comments.suki = true
  ) as ari;
end;
$$;
  • トリガーの一覧を取得する
SELECT
     a.event_object_table  AS table_name
    ,a.trigger_name AS trigger_name
    ,a.action_statement AS action_statement
    ,REPLACE(a.action_statement, 'EXECUTE FUNCTION ','') AS func_name
    ,b.tgenabled AS trigger_enable
    ,COALESCE( a.action_condition, '' ) AS action_condition
FROM
    information_schema.triggers AS a
    LEFT OUTER JOIN pg_trigger AS b ON
        a.trigger_name=b.tgname
WHERE
    a.trigger_schema = current_schema()
GROUP BY
     a.event_object_table
    ,a.trigger_name
    ,a.action_statement
    ,b.tgenabled
    ,a.action_condition
ORDER BY
    a.trigger_name
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0