Extract the uniquely identifying value of the table created by PostgreSQL

Conclusion

select relname,oid from pg_class 
where relname not like 'pg_%'
and relname not like 'sql_%' 
and relkind='r';

Background

While creating a java bulletin board, I wanted to get the creation date and time of the created table. However, it didn't seem to be easy to obtain, so I searched for another method. As a result, pg_class I decided to use a table in the DB and a table that manages the meta information of the index. As a result, the value unique to each table could be obtained.

Reference site https://www.postgresql.jp/document/9.4/html/catalog-pg-class.html

Details

・ Rellname: The name of the table -Oid: A table-specific value. Not duplicate. -Relkind: Table is r, index is i, sequence is s, and so on.

Using these, I succeeded in extracting only the table-specific values I created and their names.

Recommended Posts

Extract the uniquely identifying value of the table created by PostgreSQL
Get the object name of the instance created by the new operator
Examine the contents of the WAR file generated by the project created by Spring Initializr
[Ruby] I want to extract only the value of the hash and only the key
Get the value of enum saved in DB by Rails with attribute_before_type_cast
Samshin on the value of the hidden field
The process of understanding Gemfile by non-engineers
[Swift] Termination of the program by assertion
Use the where method to narrow down by referring to the value of another model.