select row value from column's oid - Mailing list pgsql-general

From Mathieu
Subject select row value from column's oid
Date
Msg-id 0a17a615-34a4-4d21-933b-944b6446d403@c58g2000hsc.googlegroups.com
Whole thread Raw
List pgsql-general
Hi guys.

I'd like to make a sql request able to get both row value and column
name of a table for a specific id.

Since I need the column name in my process, i first got interested in
a way to get this info from pg tables with this request :

SELECT
    a.attname as "column_name"
FROM
    pg_catalog.pg_attribute a
WHERE
a.attnum > 0
AND NOT a.attisdropped
AND a.attrelid = (
    SELECT c.oid
    FROM pg_catalog.pg_class c
    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
    WHERE c.relname = 'my_table_name_here'
    AND pg_catalog.pg_table_is_visible(c.oid)
)

This is working fine but i would like this same request to select both
my "column_name" AND my "row_value"; so i thought : "let's add a JOIN
statement and select my row value depending on my specific id and my
column name or OID or whatever i can find in my pg_attribute
table" ... but i can't find a way to do it!

Any idea? :)

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Slony vs Longiste
Next
From: Howard Cole
Date:
Subject: pg_dump of non nublic schema causes problems on restore.