Postgres - 如何在表结构查询中检索默认值

nas*_*971 0 sql postgresql

我正在尝试使用此查询检索某些表的结构以及列默认值:

SELECT column_name, is_nullable, character_maximum_length, udt_name, default_value
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'USER'
ORDER BY ordinal_position
Run Code Online (Sandbox Code Playgroud)

但我无法找到正确的值来选择默认值。我尝试了“default_value”,但它不起作用......

小智 5

手册中所述,默认值可在column_default

SELECT column_name, is_nullable, character_maximum_length, udt_name, column_default
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'USER'
ORDER BY ordinal_position
Run Code Online (Sandbox Code Playgroud)