From: | George Moga <george(at)flex(dot)ro> |
---|---|
To: | Larry Bottorff <swprenzl(at)southwind(dot)net>, SQL PostgreSQL <pgsql-sql(at)postgreSQL(dot)org> |
Subject: | Re: [SQL] int4 to varchar conversion |
Date: | 1999-01-07 16:07:16 |
Message-ID: | 3694DBB4.CCF4DB9D@flex.ro |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Larry Bottorff wrote:
> I'm doing something very typical: I created a sequence "seq" and then
> wanted to insert the NEXTVAL('seq') into a varchar field of a table to be
> used as a primary key.
>
> INSERT INTO products (prodno, ...) VALUES (NEXTVAL('seq'), 'blah',
> 'blah');
>
> Where prodno is varchar. I tried a text(...) cast, but it complains of a
> text-varchar mismatch. There is no varchar(...).
>
> Apparently, this is not possible in Postgres(?).
>
> Larry Bottorff SouthWind Internet Access, Inc.
> System Programmer 120 S. Market St. Suite 300
> swprenzl(at)southwind(dot)net Wichita, KS 67202
> ---------------------------------------------------------------------
> In Wichita:(316)263-7964 Elsewhere:1-877-525-7964
try:
INSERT INTO products (prodno, ...) VALUES (NEXTVAL('seq')::text, 'blah', ...);
Example:
test=>CREATE TABLE seq_varchar (field1 varchar(4), field2 text, primary key
(field1));
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index var_pkey for table
var
CREATE
test=>CREATE SEQUENCE seq_test;
test=>INSERT INTO seq_varchar VALUES (NEXTVAL ( 'seq_test' )::text,
'blablabla');
INSERT 741504 1
test=>SELECT * FROM seq_varchar;
field1|field2
------+---------
1|blablabla
(1 row)
test=>INSERT INTO seq_varchar VALUES (NEXTVAL ( 'seq_test' )::text,
'blahblahblah');
INSERT 741505 1
test=>SELECT * FROM seq_varchar;
field1|field2
------+------------
1|blablabla
2|blahblahblah
(2 rows)
--
Best,
George Moga,
george(at)flex(dot)ro
george(at)cicnet(dot)ro
Braila, ROMANIA
From | Date | Subject | |
---|---|---|---|
Next Message | Larry Bottorff | 1999-01-07 17:06:52 | Re: [SQL] int4 to varchar conversion |
Previous Message | Larry Bottorff | 1999-01-07 15:31:08 | int4 to varchar conversion |