Getting the primary key columns off a table I have a postgresql 11 database and I am trying to follow this official post on getting the primary key column from a table. However I get an error saying that my table is not an existing column.

ERROR:  column "tablename" does not exist
LINE 10: ...* from pg_index WHERE indisprimary AND indrelid = "tablename"...
                                                              ^


The code looks like this:

SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type
FROM   pg_index i
JOIN   pg_attribute a ON a.attrelid = i.indrelid
                     AND a.attnum = ANY(i.indkey)
WHERE  i.indrelid = "tablename"::regclass -- &lt;--- This is the problem
AND    i.indisprimary;


I believe the issue has something t do with the ::regclass cast as looking at the full table and replacing "tablename"::regclass with the indrelid number works fine, in my case it was 16490.

SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type
FROM   pg_index i
JOIN   pg_attribute a ON a.attrelid = i.indrelid
                     AND a.attnum = ANY(i.indkey)
WHERE  i.indrelid = 16490 -- "tablename"::regclass &lt;--- replace with the number
AND    i.indisprimary;


Any ideas on why the official example is not working and how I can fix it?
https://stackoverflow.com/questions/1214576/how-do-i-get-the-primary-keys-of-a-table-from-postgres-via-plpgsql ...

if schema is needed please modify slightgly to 

SELECT               
  pg_attribute.attname, 
  format_type(pg_attribute.atttypid, pg_attribute.atttypmod) 
FROM pg_index, pg_class, pg_attribute, pg_namespace 
WHERE 
  pg_class.oid = 'MY TABLE'::regclass AND 
  indrelid = pg_class.oid AND 
  nspname = 'MY CLASS' AND 
  pg_class.relnamespace = pg_namespace.oid AND 
  pg_attribute.attrelid = pg_class.oid AND 
  pg_attribute.attnum = any(pg_index.indkey)
  AND indisprimary