0

I usually use MySQL, to determine its data type, I use 'describe column_name;' but in PostgreSQL, it doesn't work. What is the correct formula to determine data types in PostgreSQL?

I tried inputting the code: describe column_name; \d table_name; but none of them worked

2
  • 1
    \d only works in the psql shell Commented Jan 8, 2024 at 13:09
  • if you have custom types, see this answer Commented Jan 8, 2024 at 13:59

1 Answer 1

2

I would query the view information_schema.columns, which should work on all standard compliant databases:

SELECT data_type, numeric_precision, numeric_scale, character_maximum_length
FROM information_schema.columns
WHERE table_schema = 'schemaname'
  AND table_name = 'tablename'
  AND column_name = 'columnname';

numeric_precision, numeric_scale and character_maximum_length are the optional type modifiers for the respective data types.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.