Re: [SQL] Sequence and nextval problem

2008-11-25 Thread Steve Midgley
At 11:20 PM 11/24/2008, [EMAIL PROTECTED] wrote: Message-Id: <[EMAIL PROTECTED]> From: ries van Twisk <[EMAIL PROTECTED]> To: Tk421 <[EMAIL PROTECTED]> In-Reply-To: <[EMAIL PROTECTED]> Subject: Re: Sequence and nextval problem Date: Mon, 24 Nov 2008 16:21:40 -0500 References: <[EMAIL PROTECTED]>

Re: [SQL] Sequence and nextval problem

2008-11-24 Thread Craig Ringer
Earlier, Craig Ringer wrote: for sample operator/cast definitions. There are some notes in the top of the "passthrough.txt" module I attached that explain the ODBC driver options you'll want. Also, note that in the message I just posted the function DSN() must be adapted to include the appro

Re: [SQL] Sequence and nextval problem

2008-11-24 Thread Craig Ringer
Tk421 wrote: Hello everybody. I've got an vb aplication that uses an Access database. I'm trying to convert the database to postgres. The conversion was done ok, but i've got a little problem that i don't know how to solve. Let's see if anyone can help me. The conversion from acces

Re: [SQL] Sequence and nextval problem

2008-11-24 Thread ries van Twisk
On Nov 24, 2008, at 2:12 PM, Tk421 wrote: Hello everybody. I've got an vb aplication that uses an Access database. I'm trying to convert the database to postgres. The conversion was done ok, but i've got a little problem that i don't know how to solve. Let's see if anyone can help me

Re: [SQL] Sequence and nextval problem

2008-11-24 Thread Scott Marlowe
On Mon, Nov 24, 2008 at 12:12 PM, Tk421 <[EMAIL PROTECTED]> wrote: > Hello everybody. > > I've got an vb aplication that uses an Access database. I'm trying to > convert the database to postgres. The conversion was done ok, but i've got a > little problem that i don't know how to solve. Let's s

Re: [SQL] sequence number in a result

2008-10-09 Thread Relyea, Mike
> Is there a function or special system label I can use that would generate a sequence number in the returning result set? Would something like this work for you? CREATE TEMP SEQUENCE foo; SELECT a, b, c, nextval('foo') AS order FROM t1 ORDER BY a; Mike Relyea Product Development Engineer Xe

Re: [SQL] sequence number in a result

2008-10-09 Thread Tom Lane
"Campbell, Lance" <[EMAIL PROTECTED]> writes: > Is there a function or special system label I can use that would > generate a sequence number in the returning result set? The usual hack is a temporary sequence: regression=# create temp sequence s1; CREATE SEQUENCE regression=# select nextval('s1'

Re: [SQL] sequence number in a result

2008-10-09 Thread Oliveiros Cristina
: Thursday, October 09, 2008 5:48 PM Subject: Re: [SQL] sequence number in a result Howdy, Lance. I had that problem about a year ago, and AFAIK there is no solution, at least not in SQL Standard. What I did was something like SELECT a,b,c,count(y.a) as order FROM t1 x , t1 y WH

Re: [SQL] sequence number in a result

2008-10-09 Thread Oliveiros Cristina
Howdy, Lance. I had that problem about a year ago, and AFAIK there is no solution, at least not in SQL Standard. What I did was something like SELECT a,b,c,count(y.a) as order FROM t1 x , t1 y WHERE ((x.a > y.a) OR (x.a = y.a AND x.ID <= y.ID)) -- Use here whatever you have as primary key

Re: [SQL] Sequence vs. Index Scan

2007-05-07 Thread Aaron Bono
On 5/7/07, Tom Lane <[EMAIL PROTECTED]> wrote: Andrew Sullivan <[EMAIL PROTECTED]> writes: > On Sun, May 06, 2007 at 01:45:54PM -0500, Aaron Bono wrote: >> So my conclusion is that the function is being treated as volatile even >> though it is stable because the number of records is small. > I

Re: [SQL] Sequence vs. Index Scan

2007-05-07 Thread Tom Lane
Andrew Sullivan <[EMAIL PROTECTED]> writes: > On Sun, May 06, 2007 at 01:45:54PM -0500, Aaron Bono wrote: >> So my conclusion is that the function is being treated as volatile even >> though it is stable because the number of records is small. > I don't think that's the issue. If this is depende

Re: [SQL] Sequence vs. Index Scan

2007-05-07 Thread Andrew Sullivan
On Sun, May 06, 2007 at 01:45:54PM -0500, Aaron Bono wrote: > Then I inserted 150 more records in the slow schema and pow - it started > working like the fast schema. > > So my conclusion is that the function is being treated as volatile even > though it is stable because the number of records i

Re: [SQL] Sequence vs. Index Scan

2007-05-06 Thread Aaron Bono
On 5/5/07, Jaime Casanova <[EMAIL PROTECTED]> wrote: On 5/5/07, Aaron Bono <[EMAIL PROTECTED]> wrote: > On 5/5/07, Tom Lane <[EMAIL PROTECTED]> wrote: > > "Aaron Bono" <[EMAIL PROTECTED]> writes: > > > 9. -> Seq Scan on branch (cost= 0.00..4.72 > rows=1 > > > width=12

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Jaime Casanova
On 5/5/07, Aaron Bono <[EMAIL PROTECTED]> wrote: On 5/5/07, Tom Lane <[EMAIL PROTECTED]> wrote: > "Aaron Bono" <[EMAIL PROTECTED]> writes: > > 9. -> Seq Scan on branch (cost=0.00..4.72 rows=1 > > width=1281) (actual time= 130129.988..157492.057 rows=1 loops=1) > > 10.

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
On 5/5/07, Tom Lane <[EMAIL PROTECTED]> wrote: "Aaron Bono" <[EMAIL PROTECTED]> writes: > 9. -> Seq Scan on branch (cost=0.00..4.72rows=1 > width=1281) (actual time=130129.988..157492.057 rows=1 loops=1) > 10.Filter: ((start_day <= now(

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
On 5/5/07, Andrew Sullivan <[EMAIL PROTECTED]> wrote: On Sat, May 05, 2007 at 05:00:53PM -0500, Aaron Bono wrote: > We don't allow deletes and updates are fairly infrequent. I also did a > vacuum analyze to no effect. How do you "not allow" deletes? Permissions are set on the tables to onl

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
On 5/5/07, Tom Lane <[EMAIL PROTECTED]> wrote: "Aaron Bono" <[EMAIL PROTECTED]> writes: > 9. -> Seq Scan on branch (cost=0.00..4.72rows=1 > width=1281) (actual time=130129.988..157492.057 rows=1 loops=1) > 10.Filter: ((start_day <= now(

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Andrew Sullivan
On Sat, May 05, 2007 at 05:00:53PM -0500, Aaron Bono wrote: > > They have different data. The fast one has about 150 rows and the slow one > has about 40 rows. The field in question here, the branch_id, is a > BIGSERIAL in both. I'd be astonished if a table of 40 rows ever got index scanned.

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Tom Lane
"Aaron Bono" <[EMAIL PROTECTED]> writes: > 9. -> Seq Scan on branch (cost=0.00..4.72 rows=1 > width=1281) (actual time=130129.988..157492.057 rows=1 loops=1) > 10.Filter: ((start_day <= now()) AND > ((end_day IS NULL) OR (end_day >= now())

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Aaron Bono
On 5/5/07, Andrew Sullivan <[EMAIL PROTECTED]> wrote: On Sat, May 05, 2007 at 04:05:52PM -0500, Aaron Bono wrote: > I have two schemas, both with the exact same DDL. One performs great and Do they have the same data? They have different data. The fast one has about 150 rows and the slow o

Re: [SQL] Sequence vs. Index Scan

2007-05-05 Thread Andrew Sullivan
On Sat, May 05, 2007 at 04:05:52PM -0500, Aaron Bono wrote: > I have two schemas, both with the exact same DDL. One performs great and Do they have the same data? > I have > checked and there IS an index, specifically a primary key index, on the > branch_id in both schemas so I cannot figure ou

Re: [SQL] Sequence vs Serial

2007-04-01 Thread Tom Lane
Scott Marlowe <[EMAIL PROTECTED]> writes: > Daniel CAUNE <[EMAIL PROTECTED]> Said: >> I was wondering when it is better to choose sequence, and when >> it is better to use serial. > One reason for using serial versus sequence is that a serial gives you > automatic dependency tracking. Note that

Re: [SQL] Sequence vs Serial

2007-04-01 Thread Scott Marlowe
Daniel CAUNE <[EMAIL PROTECTED]> Said: > I was wondering when it is better to choose sequence, and when > it is better to use serial. The serial type is a sequence with > default parameters (http://www.postgresql.org/docs/8.2/static/datatype-numeric.html#DATATYPE-SERIAL). > Actually, I never

Re: [SQL] Sequence of SQL command execution involving triggers and stored procedures.

2004-09-18 Thread Tom Lane
"Omkar Rath" <[EMAIL PROTECTED]> writes: > Say there is a stored procedure i.e FUNCTION sp_foo(...) which has say, > SQL commands (any of SELECT,INSERT,UPDATE,DELETE) in its body, say S1 > followed by S2 then S3 Furthermore, execution of statement S2 > results in trigger functions getting invok

Re: [SQL] sequence

2003-08-15 Thread Tom Lane
"cristi" <[EMAIL PROTECTED]> writes: > What is wrong here? > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); Either too few parentheses, or too many ;-) You could write this as an INSERT/SELECT: insert into table_name (field_name) select setval('seq

Re: [SQL] sequence

2003-08-15 Thread Bertrand Petit
On Fri, Aug 15, 2003 at 12:32:36PM +0300, cristi wrote: > What is wrong here? > > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); This should be better: INSERT INTO table_name (field_name) VALUES (nextval('sequence_name')); -- %!PS 2

Re: [SQL] sequence

2003-08-15 Thread Dennis Björklund
On Fri, 15 Aug 2003, cristi wrote: > What is wrong here? > > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); Your probably want this instead: insert into table_name (field_name) values (nextval('sequence_name')); The reason why your insert fail ab

Re: [SQL] SEQUENCE and PRIMARY KEY

2003-07-03 Thread Rod Taylor
> >A trigger (maybe a rule) is the way to go about this. > > > >The alternative is to teach the bad clients to use DEFAULT rather than > >NULL when they expect the GENERATOR to create the value for them. > > > Hmm, Rod, there really seems a demand for the GENERATOR feature :-) > Do you see any perf

Re: [SQL] SEQUENCE and PRIMARY KEY

2003-07-02 Thread Rod Taylor
On Wed, 2003-07-02 at 11:30, Ralf Werny wrote: > Hi, > many clients like webmin and openoffice makes an > INSERT NULL if i give no value for a field because it is a sequence. > Is there a better way to solve this problem as using a trigger ? A trigger (maybe a rule) is the way to go about th

Re: [SQL] sequence question

2003-01-27 Thread Rod Kreisler
select relname as table, attname as column from pg_class c join pg_attribute a on c.oid=a.attrelid join pg_attrdef d on a.attnum=d.adnum where adsrc='nextval(\'"SEQUENCE_NAME_SEQ"\'::text)'\ AND d.adrelid=c.oid; There may be a more efficient query, but I wasn't too worried about figuring it out...

Re: [SQL] Sequence name length

2002-07-16 Thread Rudi Starcevic
Hi Tom, Here is the output from 'select version()' PostgreSQL 7.2 on i686-pc-linux-gnu, compiled by GCC 2.95.2 Cheers Rudi. Tom Lane wrote: >Rudi Starcevic <[EMAIL PROTECTED]> writes: > > >>Just a quick one on the length of the name of a sequence. >>... >>However the sequence created is nam

Re: [SQL] Sequence name length

2002-07-16 Thread Christopher Kings-Lynne
> > However the sequence created is named : > > eselect_maincategory_maincat_id ( the '_seq' is lopped off ) > > What version are you running? Anything recent will keep the '_seq' > and lop elsewhere. Not if he's manually creating a sequence name that's too long - it will just truncate it me

Re: [SQL] Sequence name length

2002-07-16 Thread Tom Lane
Rudi Starcevic <[EMAIL PROTECTED]> writes: > Just a quick one on the length of the name of a sequence. > ... > However the sequence created is named : > eselect_maincategory_maincat_id ( the '_seq' is lopped off ) What version are you running? Anything recent will keep the '_seq' and lo

Re: [SQL] Sequence name length

2002-07-16 Thread Christopher Kings-Lynne
Hi Rudi, Unless you redefine it before compiling, postgres has a built-in limit of 31 characters for names. Increasing this has a performance penalty, but it might happen for 7.3 due to some improvements in the performance area. BTW, the best way to do a sequence primary key is lik ethis: crea

Re: [SQL] sequence chages after firing update

2002-06-26 Thread Rajesh Kumar Mallah.
dear subha, Use explicit ORDER BY if u want to order the records by some column. otherwise the order of output from a select stmt is undefined. bu generally it is found the the last updated record comes last. On Wednesday 26 June 2002 17:17, Subhashini Karthikeyan wrote: > hi all > > > In post

Re: [SQL] sequence chages after firing update

2002-06-26 Thread Stephan Szabo
On Wed, 26 Jun 2002, Subhashini Karthikeyan wrote: > In postgresql 7.1.3 > > i am updateing a row. it is a 4th record. > after updation if i am firing a select query it is > coming as a last record ..what shall i do to avoid > that.. > any help appriciated If I understand the complaint, use an

Re: [SQL] Sequence behaviour.

2001-06-19 Thread Grant
> > binary_data=# create sequence test; > > CREATE > > binary_data=# select nextval('test'); > > NOTICE: test.nextval: sequence was re-created > > Um, how did you get that NOTICE? I don't see it. This is version 7.0.3. I deleted the sequence first. > Anyway, the answer to your question is tha

Re: [SQL] Sequence behaviour.

2001-06-18 Thread Tom Lane
Grant <[EMAIL PROTECTED]> writes: > Why is the following like it is? I would think that nextval would return 2 > in both instances, am I missing something here? :) Thanks! > binary_data=# create sequence test; > CREATE > binary_data=# select nextval('test'); > NOTICE: test.nextval: sequence was

Re: [SQL] sequence problem

2001-05-21 Thread Stephan Szabo
On Mon, 21 May 2001, gabi munteanu wrote: > I have the following problem. > > I have a table [friends] and it looks like this: >id serial >name varchar(25) >phone varchar(15) > After I created it tehre is also a sequence that generates me the ids > friens_id_s