Skip to content

Create get-oid-table-postgresql.sql #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--get oid using pg_class
SELECT oid, relname
FROM pg_class
WHERE relname = 'student';

--get oid using pg_catalog.pg_class with pg_catalog.pg_namespace
SELECT c.oid, n.nspname AS schema_name, c.relname AS table_name
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = 'student' AND n.nspname = 'public';

--get oid using pg_table_is_visible() and pg_class
SELECT c.oid, c.relname AS table_name
FROM pg_class c
WHERE c.relname = 'student' AND pg_table_is_visible(c.oid);

--get oid using regclass cast
SELECT 'public.student'::regclass::oid;

--Listing OIDs of All Tables
SELECT c.oid, n.nspname AS schema_name, c.relname AS table_name
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind = 'r';