hot to determine calculated fields (views) - Mailing list pgsql-general

From will trillich
Subject hot to determine calculated fields (views)
Date
Msg-id 20030125064507.GA27730@mail.serensoft.com
Whole thread Raw
Responses Re: hot to determine calculated fields (views)
List pgsql-general
the lights are beginning to glow. :)

those pg_* tables are really something! but how can i tell if an
attribute of a relation (field of a table) is calculated via a
view, or actual data from a table?

i'm trying to use the pg_* system tables in some views that'll
help my app determine various aspects of fields in the database,
such as how much of a limit to impose on data entry (varchar(20)
should get <input type="text" maxlength="20" ...> for example).

    create view sys_field_size as
    SELECT
        c.relname   as class,
        a.attname   as field,
        a.attlen    as storage,
        a.attnum    as field_no,
        a.atttypmod as field_mod,
        CASE
            WHEN a.atttypmod<=0
                THEN CASE
                    WHEN a.attlen<0
                        THEN -1
                    ELSE
                        NULL
                END
            ELSE
                a.atttypmod - 4
        END
            AS SIZE
    FROM
        pg_attribute a
            JOIN
        pg_class c
                ON c.oid = a.attrelid
    WHERE
        a.attnum > 0 -- only user-defined fields, thanks
        AND
        c.relname !~ '^pg_' -- not a postgres system table
        AND
        c.relkind IN ('v','r') -- view or relation/table
    ;

well, it's a start.

i've got tables (_name) and related views (name) where the views
do some munging to the fields for display, or they add new fields
based on the actual data in the table. for html-generation, i
don't want the calculated fields looking like data entry is
possible, so i need to distinguish them from the editable ones.

QUESTION:

how can i tell whether i'm looking at a computed field (from a
view) as opposed to actual data (brought in directly from a
table)? something in pg_attribute, i hope... :)

--
There are 10 kinds of people:
ones that get binary, and ones that don't.

will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Looking for a firewall? Do you think smoothwall sucks? You're
probably right... Try the folks at http://clarkconnect.org/ !

pgsql-general by date:

Previous
From: Shridhar Daithankar
Date:
Subject: Re: Documentation needs significant improvement
Next
From: Tom Lane
Date:
Subject: Re: Documentation needs significant improvement