Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Supplying a def...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3473 of 3799
Post > Topic >>

Supplying a default on read, if a column does not exist in DB

by bryce2@[EMAIL PROTECTED] (Bryce Nesbitt) May 19, 2008 at 02:48 PM

Is there a clean way in Postgres to specify a default return value, if a 
column does not exist in a database?  In pseudocode:

select p_email,
CASE WHEN EXISTS("p_email_alt") THEN p_email_alt ELSE 'none' END
from eg_application;

I can kind of almost get there with:

select p_email,
CASE WHEN EXISTS(SELECT * FROM information_schema.columns
WHERE table_schema='public' and table_catalog='stage' and 
table_name='eg_application' and column_name='p_email_alt')
THEN p_email_alt ELSE 'none' END
from eg_application;

Except that Postgres evaluates the non-existent column name in the 
"THEN", and errors out, even though the test will be false.

Note that use of stored procedures won't work for my particular use case.

             -Bryce

Google Keywords: "if column exists", "if column defined", test for 
existence of column, default column value, defaults, information schema, 
existence, definition, missing column.

-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 1 Posts in Topic:
Supplying a default on read, if a column does not exist in DB
bryce2@[EMAIL PROTECTED]   2008-05-19 14:48:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:36:44 CST 2008.