This is a discussion on Select default values within the pgsql Sql forums, part of the PostgreSQL category; --> On Wed, Jul 23, 2008 at 3:57 AM, Maximilian Tyrtania <maximilian.tyrtania@onlinehome.de> wrote: > Hi, > >> am Wed, dem ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Wed, Jul 23, 2008 at 3:57 AM, Maximilian Tyrtania <maximilian.tyrtania@onlinehome.de> wrote: > Hi, > >> am Wed, dem 23.07.2008, um 10:32:58 +0200 mailte Maximilian Tyrtania >> folgendes: >>> Hi there, just a quickie: Is there a way to select all default values of a >>> given table? Something like "Select Default values from sometable" ? >> >> test=# create table t_with_defaults( s1 int default 1, s2 int default 2); >> CREATE TABLE >> test=*# select ordinal_position, column_name, column_default from >> information_schema.columns where table_name='t_with_defaults' order by 1; >> ordinal_position | column_name | column_default >> ------------------+-------------+---------------- >> 1 | s1 | 1 >> 2 | s2 | 2 >> (2 rows) > > This is probably what I should do, the only problem is that the output of > the given query looks a lot less nice when the default looks like this > > nextval('mitarbeiter_serial'::regclass) > > I'd prefer to just receive the actual value of that function. Okay, I could > just execute that statement, but, hmm, still, that seems akward. Until you run that function, you don't know what the output might be because of possible race condtitions. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql |
| |||
| On 23/lug/08, at 11:28, Pavel Stehule wrote: > Hello > > 2008/7/23 Maximilian Tyrtania <maximilian.tyrtania@onlinehome.de>: >> Hi there, just a quickie: Is there a way to select all default >> values of a >> given table? Something like "Select Default values from sometable" ? >> Unfortunately this syntax doesn't seem to be supported. I know i >> can select >> the default values for each column, but being able to select them >> in one go >> would be handy... > > > it's not possible directly, you can find expressions used as default > in system tables or > postgres=# create table f(a integer default 1, b integer); > CREATE TABLE > postgres=# insert into f(a,b) values(default, default) returning *; It seems that you can’t use the same syntax with function calls: select function(default,default); gives a syntax error. Is it expected? -- Giorgio Valoti -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql |
| |||
| Giorgio Valoti wrote: > >> postgres=# insert into f(a,b) values(default, default) returning *; > > It seems that you can’t use the same syntax with function calls: > select function(default,default); > gives a syntax error. Is it expected? Um - there is no default value for a function. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql |
| |||
| On 24/lug/08, at 12:42, Richard Huxton wrote: > Giorgio Valoti wrote: >>> postgres=# insert into f(a,b) values(default, default) returning *; >> It seems that you can’t use the same syntax with function calls: >> select function(default,default); >> gives a syntax error. Is it expected? > > Um - there is no default value for a function. Yes, but you could define a domain with a default value and using it as an IN argument for a function. In that case it would handy to be able to use the default value, wouldn’t it? Without this "feature" you have to overload the function arguments. -- Giorgio Valoti -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql |
| |||
| On Thu, Jul 24, 2008 at 12:35 PM, Giorgio Valoti <giorgio_v@mac.com> wrote: >> Um - there is no default value for a function. > > Without this "feature" you have to overload > the function arguments. You could pass a casted null to the function. The would eliminate function overloading. Then internally you could handle the null by passing DEFAULTS to you INSERT or UPDATE statements. I don't know if this would work for you in this case. -- Regards, Richard Broersma Jr. Visit the Los Angles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql |
| ||||
| On 24/lug/08, at 23:15, Richard Broersma wrote: > On Thu, Jul 24, 2008 at 12:35 PM, Giorgio Valoti > <giorgio_v@mac.com> wrote: > >>> Um - there is no default value for a function. >> >> Without this "feature" you have to overload >> the function arguments. > > You could pass a casted null to the function. The would eliminate > function overloading. Then internally you could handle the null by > passing DEFAULTS to you INSERT or UPDATE statements. I don't know if > this would work for you in this case. It could work but only if I use a domain that allows NULLs, which reduces the usefulness of domains even if you can work around that by simply stating the not null clause in the table definition. -- Giorgio Valoti -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql |