0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

こちらの質問に対する Command-R+ の一次回答です。
生成AI で PostgreSQL の SQL を作成

SELECT
    b.table_name AS table_b_name,
    a.column_name IS NOT DISTINCT FROM b.column_name AS column_match,
    a.is_nullable = FALSE AND b.is_nullable = TRUE AS not_null_mismatch
FROM information_schema.columns a
JOIN information_schema.columns b ON a.column_name = b.column_name
    AND a.table_name = 'table_a'
    AND b.table_name <> 'table_a'
    AND b.table_schema = 'your_schema_name'
WHERE a.table_schema = 'your_schema_name'
AND a.column_name = b.column_name
AND a.is_nullable = FALSE
AND (b.is_nullable = TRUE OR b.column_default IS NOT NULL)
GROUP BY b.table_name, a.column_name, a.is_nullable, b.is_nullable, b.column_default;

実行結果

ERROR:  operator does not exist: information_schema.yes_or_no = boolean
行 4:     a.is_nullable = FALSE AND b.is_nullable = TRUE AS not_nu...
                        ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?