Thread: select only default

select only default

From
Nabil Sayegh
Date:
Hi all,

just for curiosity:

Is it possible to SELECT a row that consists only of default values of a
table ?

Let's suppose I have a Table:

CREATE TEMP TABLE tempo
(
 a int DEFAULT 5,
 b text DEFAULT 'five'
);

I want as a result:

(5, 'five')

But without inserting a row.

Is this possible with 1 query ?

I thought of something like OUTER JOINS where you get defaults for
non-existing rows, too.

What I need this for ?
I want to present users a form for inserting new rows. The form should
be loaded with default values.

Of course I can do it without SQL, but I thought, hey, that'd be cool in
plain SQL.

BTW: The DEFAULT values are all 'simple' types, no serials etc. included

TIA
--
 e-Trolley Sayegh & John, Nabil Sayegh
 Tel.: 0700 etrolley /// 0700 38765539
 Fax.: +49 69 8299381-8
 PGP : www.e-trolley.de


Re: select only default

From
Bruno Wolff III
Date:
On Fri, May 16, 2003 at 01:32:03 +0200,
  Nabil Sayegh <postgresql@e-trolley.de> wrote:
> Hi all,
>
> just for curiosity:
>
> Is it possible to SELECT a row that consists only of default values of a
> table ?

There is probably some way to get the data out of the system tables. If
the defaults are constants you might be able to easily present it.

However, for what you are doing it may be better to put the defaults
in a separate table and get them from there. You will have to create
a function(s) for getting the default values since you can't use
select in a default clause.

Re: select only default

From
"Ville Jungman"
Date:
default values are id pg_attrdef table. you should join pg_class-table with
it because it contains column names.

this query should solve (at least a part of) your problem:

select a.adsrc from pg_attrdef a,pg_class c where a.adrelid=c.relfilenode
and c.relname='tablename';

, where 'tablename' is the name of your table.

ville jungman, ulvilantie 3 b 11, 00350 helsinki, finland
tel. + 358 - 9 - 225 4482 , http://www.kolumbus.fi/vilmak
usko Herraan Jeesukseen, niin sin� pelastut. (apt. 16:31)




>From: Bruno Wolff III <bruno@wolff.to>
>To: Nabil Sayegh <postgresql@e-trolley.de>
>CC: pgsql-novice <pgsql-novice@postgresql.org>
>Subject: Re: [NOVICE] select only default
>Date: Thu, 15 May 2003 21:30:59 -0500
>
>On Fri, May 16, 2003 at 01:32:03 +0200,
>   Nabil Sayegh <postgresql@e-trolley.de> wrote:
> > Hi all,
> >
> > just for curiosity:
> >
> > Is it possible to SELECT a row that consists only of default values of a
> > table ?
>
>There is probably some way to get the data out of the system tables. If
>the defaults are constants you might be able to easily present it.
>
>However, for what you are doing it may be better to put the defaults
>in a separate table and get them from there. You will have to create
>a function(s) for getting the default values since you can't use
>select in a default clause.
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail