[SQL] get sequence value of insert command

2004-11-19 Thread Erik Thiele
hi create sequence mysequence; create table foo( id integer default nextval('mysequence'), bla text, wombat integer, foobar date, primary key(id) ); insert into foo (wombat) values (88); now how do i know the id of my newly inserted element? and how can this be done in a completely co

Re: [SQL] get sequence value of insert command

2004-11-19 Thread Achilleus Mantzios
O Erik Thiele έγραψε στις Nov 19, 2004 : > hi > > create sequence mysequence; > > create table foo( > id integer default nextval('mysequence'), > bla text, > wombat integer, > foobar date, > primary key(id) > ); > > insert into foo (wombat) values (88); > > now how do i know the id o

Re: [SQL] get sequence value of insert command

2004-11-19 Thread Richard Huxton
Achilleus Mantzios wrote: now how do i know the id of my newly inserted element? and how can this be done in a completely concurrency safe way? The way to do this is by reading the docs :) use currval, it is session safe. The increase in this question suggests the number of new users has increase

Re: [SQL] get sequence value of insert command

2004-11-19 Thread Michael Glaesemann
On Nov 19, 2004, at 5:41 PM, Erik Thiele wrote: now how do i know the id of my newly inserted element? and how can this be done in a completely concurrency safe way? This is a FAQ (4.15.1, among others). See currval() and nextval() in the documentation as well. Michael Glaesemann grzm myrealbox c

Re: [SQL] get sequence value of insert command

2004-11-19 Thread Iain
I seem to recall it was mine. I made the mistake of assuming it wasn't concurrency safe and was gently corrected by one of the community. I think it might have been a Tim/Tam Lane. Wonder what happened to him? :-) M tim tams rgds Homer ---(end of broadcast)

[SQL] transactions in functions, possible bug or what I'm doing wrong?

2004-11-19 Thread Riccardo G. Facchini
Hi All, PostgreSQL 7.4.5 assume this script: --- create table test_table ( id serial, test_value text ) without oids; insert into test_table (test_value) values ('A'); insert into test_table (test_value) values ('B'); insert into test_table (test_value) values ('C'); insert into test_table

Re: [SQL] transactions in functions, possible bug or what I'm doing

2004-11-19 Thread Richard Huxton
Riccardo G. Facchini wrote: Why does select test_without_transaction(); return this info: "ABCD" (as should be) and select test_with_transaction(); returns this error? ERROR: SPI_prepare() failed on "start transaction" CONTEXT: PL/pgSQL function "test_with_transaction" line 6 at SQL statement I'v

[SQL] CREATE TEMPORARY TABLE .. ON COMMIT DROP question

2004-11-19 Thread Riccardo G. Facchini
Hi all, I'm trying to understand where the "[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]" is stored when defining a temporary table. whenever a table is created, a record in the pg_class is stored with the info regarding the table, but I haven't been able to locate where the info regardin

Re: [SQL] CREATE TEMPORARY TABLE .. ON COMMIT DROP question

2004-11-19 Thread Tom Lane
"Riccardo G. Facchini" <[EMAIL PROTECTED]> writes: > I'm trying to understand where the "[ ON COMMIT { PRESERVE ROWS | > DELETE ROWS | DROP } ]" is stored when defining a temporary table. I don't believe it's stored anyplace visible :-(. There's some private state in the memory of the backend tha

Re: [SQL] CREATE TEMPORARY TABLE .. ON COMMIT DROP question

2004-11-19 Thread Riccardo G. Facchini
--- Tom Lane <__> wrote: > "Riccardo G. Facchini" <[EMAIL PROTECTED]> writes: > > I'm trying to understand where the "[ ON COMMIT { PRESERVE ROWS | > > DELETE ROWS | DROP } ]" is stored when defining a temporary table. > > I don't believe it's stored anyplace visible :-(. There's some > private

Re: [SQL] Comparing Dates

2004-11-19 Thread Guy Fraser
You should use single quotes for all literals. Examples: select '2004-06-08' ; ?column? 2004-06-08 select 'user' ; ?column? -- user Failing to quote literals will cause unexpected results. Examples: select 2004-06-08 ; ?column? -- 1990 select user ; current_user --

Re: [SQL] get sequence value of insert command

2004-11-19 Thread Passynkov, Vadim
> -Original Message- > From: Erik Thiele [mailto:[EMAIL PROTECTED] > Sent: Friday, November 19, 2004 3:42 AM > To: [EMAIL PROTECTED] > Subject: [SQL] get sequence value of insert command > > > hi > > create sequence mysequence; > > create table foo( > id integer default nextval('mys

Re: [SQL] transactions in functions, possible bug or what I'm doing

2004-11-19 Thread Michael Fuhr
On Fri, Nov 19, 2004 at 12:59:07PM +, Richard Huxton wrote: > You can have what are called "savepoints" in version 8.0 though, which > lets you trap errors and rollback to a named (saved) point in your function. Savepoints in functions don't work as of 8.0.0beta4, unless I'm doing something

Re: [SQL] transactions in functions, possible bug or what I'm doing

2004-11-19 Thread Tom Lane
Michael Fuhr <[EMAIL PROTECTED]> writes: > On Fri, Nov 19, 2004 at 12:59:07PM +, Richard Huxton wrote: >> You can have what are called "savepoints" in version 8.0 though, which >> lets you trap errors and rollback to a named (saved) point in your function. > Savepoints in functions don't work

[SQL] NULLS and string concatenation

2004-11-19 Thread Don Drake
I have a function that uses an execute statement to insert data into a table, I do in my implementation of table partitioning. Anyway, I ran into trouble when NULL values were being passed in (fields are nullable) and my insert statement turned into a big NULL. Here's an equivalent statement that

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Bruno Wolff III
On Fri, Nov 19, 2004 at 11:12:38 -0600, Don Drake <[EMAIL PROTECTED]> wrote: > I have a function that uses an execute statement to insert data into a > table, I do in my implementation of table partitioning. > > Anyway, I ran into trouble when NULL values were being passed in > (fields are nulla

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Michael Fuhr
On Fri, Nov 19, 2004 at 11:45:43AM -0600, Bruno Wolff III wrote: > On Fri, Nov 19, 2004 at 11:12:38 -0600, Don Drake <[EMAIL PROTECTED]> wrote: > > > > I was able to work around the problem by using COALESCE (and casting > > variables since it wants the same data types passed to it). > > This is

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Richard Huxton
Don Drake wrote: select 'some text, should be null:'|| NULL This returns NULL and no other text. Why is that? I wasn't expecting the "some text.." to disappear altogether. Is this a bug? No. Null is "unknown" if you append unknown (null) to a piece of text, the result is unknown (null) too. If

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Don Drake
On Fri, 19 Nov 2004 17:48:34 +, Richard Huxton <[EMAIL PROTECTED]> wrote: > Don Drake wrote: > > select 'some text, should be null:'|| NULL > > > > This returns NULL and no other text. Why is that? I wasn't expecting > > the "some text.." to disappear altogether. > > > > Is this a bug? > > N

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Stephan Szabo
On Fri, 19 Nov 2004, Don Drake wrote: > On Fri, 19 Nov 2004 17:48:34 +, Richard Huxton <[EMAIL PROTECTED]> wrote: > > Don Drake wrote: > > > select 'some text, should be null:'|| NULL > > > > > > This returns NULL and no other text. Why is that? I wasn't expecting > > > the "some text.." to

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Tom Lane
Don Drake <[EMAIL PROTECTED]> writes: > This is still strange to me. In Oracle, the same query would not > replace the *entire* string with a NULL, it treats the NULL as a no > value. Oracle is a bit, um, standards-challenged. They fail to make a distinction between an empty string and a NULL, b

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Gregory S. Williamson
Someone on this list provided me with a rather elegant solution to this a few weeks ago: CREATE OR REPLACE FUNCTION text_concat_nulls_with_an_embedded_space(text, text) RETURNS text AS 'SELECT CASE WHEN $1 IS NULL THEN $2 WHEN $2 IS NULL THEN $1 ELSE $1 || '' '' || $2 END' LANGUAGE sql; CREAT

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Terry Lee Tucker
Slick ;o) This goes in my tool kit... On Friday 19 November 2004 03:03 pm, Gregory S. Williamson saith: > Someone on this list provided me with a rather elegant solution to this a > few weeks ago: > > CREATE OR REPLACE FUNCTION text_concat_nulls_with_an_embedded_space(text, > text) RETURNS text A

Re: [SQL] NULLS and string concatenation

2004-11-19 Thread Don Drake
On Fri, 19 Nov 2004 15:01:42 -0500, Tom Lane <[EMAIL PROTECTED]> wrote: > Don Drake <[EMAIL PROTECTED]> writes: > > This is still strange to me. In Oracle, the same query would not > > replace the *entire* string with a NULL, it treats the NULL as a no > > value. > > Oracle is a bit, um, standard