Skip to content

Instantly share code, notes, and snippets.

View ahkarm's full-sized avatar
:octocat:

Ahkar Min Myat ahkarm

:octocat:
View GitHub Profile
@ahkarm
ahkarm / psql_define_pk.sql
Created September 18, 2025 07:34
define pk in Postgres
DO $$
DECLARE
sql_text text;
BEGIN
SELECT string_agg(
'ALTER TABLE ' || quote_ident(table_schema) || '.' || quote_ident(table_name) ||
' ADD CONSTRAINT pk_' || table_name ||
' PRIMARY KEY (' || quote_ident(column_name) || ');',
E'\n'
)