CREATE TABLE AS SELECT - Mailing list pgsql-sql

From Jeff Boes
Subject CREATE TABLE AS SELECT
Date
Msg-id 42EA62DC.4060205@endpoint.com
Whole thread Raw
Responses Re: CREATE TABLE AS SELECT
List pgsql-sql
Offered up because I have no explanation, and curiosity overwhelms me:

I was attempting to create a table from a SELECT statement against
another table:

create table foo
as selecta,f(b)
from xxx;

The function f() attempts to make a unique value based on its argument
(it's actually a "username" constructor, making "jboes" out of "Jeff
Boes"). The odd thing is that function f() also looks into the table
"foo" to see if the value it's constructing is truly unique; if it is
not, it tacks on a "1", "2", etc. until it gets a unique value.

The odd behavior is as follows: with a "CREATE TABLE ... AS SELECT"
statement, the function never found duplicate values, so I ended up with
f(a) = f(a') = f(a''), etc. I tried defining the function as STABLE,
then VOLATILE, without success. But if I changed to create the table
first, and then do "INSERT INTO ... SELECT", the function worked properly.


pgsql-sql by date:

Previous
From: gherzig@fmed.uba.ar
Date:
Subject: Re: calling EXECUTE on any exception
Next
From: daq
Date:
Subject: Re: CREATE TABLE AS SELECT