pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedint4 to varchar conversion
3+ messages / 2 participants
[nested] [flat]
* int4 to varchar conversion
@ 1999-01-07 15:31 Larry Bottorff <swprenzl@southwind.net>
0 siblings, 1 reply; 3+ messages in thread
From: Larry Bottorff @ 1999-01-07 15:31 UTC (permalink / raw)
To: pgsql-sql
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@southwind.net Wichita, KS 67202
---------------------------------------------------------------------
In Wichita:(316)263-7964 Elsewhere:1-877-525-7964
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] int4 to varchar conversion
@ 1999-01-07 16:07 George Moga <george@flex.ro>
parent: Larry Bottorff <swprenzl@southwind.net>
0 siblings, 1 reply; 3+ messages in thread
From: George Moga @ 1999-01-07 16:07 UTC (permalink / raw)
To: Larry Bottorff <swprenzl@southwind.net>; 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@southwind.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@flex.ro
george@cicnet.ro
Braila, ROMANIA
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] int4 to varchar conversion
@ 1999-01-07 17:06 Larry Bottorff <swprenzl@southwind.net>
parent: George Moga <george@flex.ro>
0 siblings, 0 replies; 3+ messages in thread
From: Larry Bottorff @ 1999-01-07 17:06 UTC (permalink / raw)
To: George Moga <george@flex.ro>; +Cc: pgsql-sql
Tried your suggestion, but. . . .
=> create table seq_varchar (field1 varchar(4), field2 text, CONSTRAINT
pk_sq PRIMARY KEY (field1));
=> insert into seq_varchar values (NEXTVAL ( 'seq_test' )::text,
'blablabla');
ERROR: parser: attribute 'field1' is of type 'varchar' but expression is
of type 'text'
Is this a version or settings issue? We're not 6.4, I know that much. . .
Larry Bottorff SouthWind Internet Access, Inc.
System Programmer 120 S. Market St. Suite 300
swprenzl@southwind.net Wichita, KS 67202
---------------------------------------------------------------------
In Wichita:(316)263-7964 Elsewhere:1-877-525-7964
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~1999-01-07 17:06 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-01-07 15:31 int4 to varchar conversion Larry Bottorff <swprenzl@southwind.net>
1999-01-07 16:07 ` George Moga <george@flex.ro>
1999-01-07 17:06 ` Larry Bottorff <swprenzl@southwind.net>
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