pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frederic boucher <dziablo@hotmail.com>
To: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] create table with default value...
Date: Fri, 05 Nov 1999 10:33:16 PST
Message-ID: <19991105183316.21030.qmail@hotmail.com> (raw)



Hi,

First, thanks a lot for your answer... I had this possibility in mind but I 
wasn't sure about the security of this...  Is it possible for an other 
thread to request NEXTVAL('u_id_seq') in the middle of the creation of a 
record?  Because if this is possible the unique id would be let's say 1 and 
the concatenation would be 2 (because the "new" last_value as been 
changed)...?!?!

I'm not sure I'm quite clear ...

Second, to answer your question "Why are you wanting this?" it's because, 
like the create string says, it a DEFAULT value...  for lazy, or stupid user 
that would put anything unusefull in there...  But it can be changed too an 
must me remebered...  Isnt it the right way to do this?

Third, A simple one :  How can I get the current datetime?  like a oracle's 
"select sysdate from dual;"

Thanks

PS:  By the way, where could I find difference, or exact definition, of data 
type... Like what's the difference between "text" and "varchar"  or between 
"integer" and "int8" (in this case I suppose that integer is "int4"



>
>Salut Frederic,
>
>Not quite sure why you'd want to do what you're asking to do but the
>following works:
>
>DROP TABLE prova1;
>CREATE TABLE prova1 (
>u_id int8 DEFAULT nextval('u_id_seq'),
>name varchar(50) DEFAULT 'NT_' || currval('u_id_seq'),
>extra_field text
>);
>
>test=> select * from prova1;
>u_id|name|extra_field
>----+----+-----------
>(0 rows)
>
>test=> insert into prova1 (extra_field) values ('look');
>INSERT 2217966 1
>test=> insert into prova1 (extra_field) values ('no');
>INSERT 2217967 1
>test=> insert into prova1 (extra_field) values ('hands!');
>INSERT 2217968 1
>test=> select * from prova1;
>u_id|name|extra_field
>----+----+-----------
>    1|NT_1|look
>    2|NT_2|no
>    3|NT_3|hands!
>(3 rows)
>
>test=>
>
>The reason why I'm not quite sure why you'd want to do this is that the
>field name would be redundant.  You could simply obtain it using a select.
>e.g.:
>
>test=> SELECT u_id, 'NT_'::text || u_id::text AS name, extra_field FROM
>prova1;
>u_id|name|extra_field
>----+----+-----------
>    1|NT_1|look
>    2|NT_2|no
>    3|NT_3|hands!
>(3 rows)
>
>test=>
>
>HTH,
>
>Regards,
>
>Stuart.
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com



view thread (4+ messages)  latest in thread

Message-ID: <19991105183316.21030.qmail@hotmail.com>
Permalink:  ../19991105183316.21030.qmail@hotmail.com/
Also on:    postgresql.org/message-id/19991105183316.21030.qmail@hotmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: dziablo@hotmail.com
  Subject: Re: [SQL] create table with default value...
  In-Reply-To: <19991105183316.21030.qmail@hotmail.com>
  References: <19991105183316.21030.qmail@hotmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox