Unix Technical Forum

Select default values

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 ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 07-23-2008, 10:30 PM
Scott Marlowe
 
Posts: n/a
Default Re: Select default values

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 07-28-2008, 05:43 PM
Giorgio Valoti
 
Posts: n/a
Default Re: Select default values


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 07-28-2008, 05:43 PM
Richard Huxton
 
Posts: n/a
Default Re: Select default values

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 07-28-2008, 05:43 PM
Giorgio Valoti
 
Posts: n/a
Default Re: Select default values


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 07-28-2008, 05:43 PM
Richard Broersma
 
Posts: n/a
Default Re: Select default values

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 07-28-2008, 05:43 PM
Giorgio Valoti
 
Posts: n/a
Default Re: Select default values


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:30 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com