postgresqlextended-properties

How to add extended properties in PostgreSQL


Is it possible to add a kind of Extended Properties in tables and/or columns in PostgreSQL as we can do in SQL Server?

I've been looking for this in Google, but I can't find anything about it.

I want to describe columns (data dictionary) and add parameters that I can later match by reflection with my properties in Java.


Solution

  • Postgres (and many other DBMS) does this through a DDL statement comment on.

    To attach a comment to a table, view, column, foreign key (pretty much everything) use comment on, e.g:

    comment on table orders is 'Our orders';
    comment on column orders.amount is 'Total amount of this order';
    

    More details in the manual: http://www.postgresql.org/docs/current/static/sql-comment.html

    The JDBC driver will return this information in the remarks column in the result of e.g. getTables() or getColumns()

    To access the values through SQL, use the functions provided by Postgres:
    http://www.postgresql.org/docs/current/static/functions-info.html#FUNCTIONS-INFO-COMMENT-TABLE