From: | will trillich <will(at)serensoft(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | hot to determine calculated fields (views) |
Date: | 2003-01-25 06:45:09 |
Message-ID: | 20030125064507.GA27730@mail.serensoft.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)serensoft(dot)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/ !
From | Date | Subject | |
---|---|---|---|
Next Message | will trillich | 2003-01-25 06:53:26 | Re: Documentation needs significant improvement |
Previous Message | Shridhar Daithankar | 2003-01-25 06:39:36 | Re: Documentation needs significant improvement |