pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedERROR: syntax error at or near "select" at character 9
4+ messages / 3 participants
[nested] [flat]
* ERROR: syntax error at or near "select" at character 9
@ 2005-09-02 07:26 Graf László <graf.laszlo@axis.hu>
2005-09-06 04:35 ` Re: ERROR: syntax error at or near "select" at character 9 Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 1 reply; 4+ messages in thread
From: Graf László @ 2005-09-02 07:26 UTC (permalink / raw)
To: pgsql-sql; peter_e@gmx.net
Hi
I am using PG 8.0 on Win32, learning SQL.
I dod create a table with the following SQL:
CREATE TABLE test (
id integer,
nev varchar(25),
datum timestamp
);
A sequence with:
CREATE SEQUENCE "public"."test_azon_seq"
INCREMENT 1 MINVALUE 101
MAXVALUE 9223372036854775807 START 101
CACHE 1
;
A before insert trigger:
CREATE FUNCTION test_verif() RETURNS trigger AS $test_verif$
BEGIN
NEW.id := select nextval('test_azon_seq');
NEW.nev := nev;
NEW.datum := current_timestamp;
RETURN NEW;
END;
$test_verif$ LANGUAGE plpgsql
;
CREATE TRIGGER test_verif BEFORE INSERT ON test
FOR EACH ROW EXECUTE PROCEDURE test_verif()
;
When I issue the
insert into "public"."test" (nev) values ('Graf László');
insert statement, it returns
"ERROR: syntax error at or near "select" at character 9".
Why? What is wrong?
--
László Graf
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ERROR: syntax error at or near "select" at character 9
2005-09-02 07:26 ERROR: syntax error at or near "select" at character 9 Graf László <graf.laszlo@axis.hu>
@ 2005-09-06 04:35 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2005-09-06 08:57 ` Re: ERROR: syntax error at or near "select" at character 9 Harald Fuchs <hf0614x@protecting.net>
0 siblings, 1 reply; 4+ messages in thread
From: Stephan Szabo @ 2005-09-06 04:35 UTC (permalink / raw)
To: Graf László <graf.laszlo@axis.hu>; +Cc: pgsql-sql; peter_e@gmx.net
On Fri, 2 Sep 2005, [ISO-8859-2] Graf László wrote:
>
> CREATE FUNCTION test_verif() RETURNS trigger AS $test_verif$
> BEGIN
> NEW.id := select nextval('test_azon_seq');
I think you want to remove select here, you're already effectively doing a
select of the right hand side in the assignment.
> NEW.nev := nev;
I think you want to remove this line entirely. What nev were you
expecting on the right hand side? If it's the new one, well, NEW.new is
already that.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ERROR: syntax error at or near "select" at character 9
2005-09-02 07:26 ERROR: syntax error at or near "select" at character 9 Graf László <graf.laszlo@axis.hu>
2005-09-06 04:35 ` Re: ERROR: syntax error at or near "select" at character 9 Stephan Szabo <sszabo@megazone.bigpanda.com>
@ 2005-09-06 08:57 ` Harald Fuchs <hf0614x@protecting.net>
2005-09-06 14:00 ` Re: ERROR: syntax error at or near "select" at character 9 Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 1 reply; 4+ messages in thread
From: Harald Fuchs @ 2005-09-06 08:57 UTC (permalink / raw)
To: pgsql-sql
In article <20050905213103.F5782@megazone.bigpanda.com>,
Stephan Szabo <sszabo@megazone.bigpanda.com> writes:
> On Fri, 2 Sep 2005, [ISO-8859-2] Graf László wrote:
>>
>> CREATE FUNCTION test_verif() RETURNS trigger AS $test_verif$
>> BEGIN
>> NEW.id := select nextval('test_azon_seq');
> I think you want to remove select here, you're already effectively doing a
> select of the right hand side in the assignment.
>> NEW.nev := nev;
> I think you want to remove this line entirely. What nev were you
> expecting on the right hand side? If it's the new one, well, NEW.new is
> already that.
László could also remove the entire trigger and use something like
CREATE TABLE test (
id SERIAL NOT NULL,
nev VARCHAR(25),
datum TIMESTAMP NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (id)
);
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ERROR: syntax error at or near "select" at character 9
2005-09-02 07:26 ERROR: syntax error at or near "select" at character 9 Graf László <graf.laszlo@axis.hu>
2005-09-06 04:35 ` Re: ERROR: syntax error at or near "select" at character 9 Stephan Szabo <sszabo@megazone.bigpanda.com>
2005-09-06 08:57 ` Re: ERROR: syntax error at or near "select" at character 9 Harald Fuchs <hf0614x@protecting.net>
@ 2005-09-06 14:00 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 0 replies; 4+ messages in thread
From: Stephan Szabo @ 2005-09-06 14:00 UTC (permalink / raw)
To: Harald Fuchs <hf0614x@protecting.net>; +Cc: pgsql-sql
On Tue, 6 Sep 2005, Harald Fuchs wrote:
> In article <20050905213103.F5782@megazone.bigpanda.com>,
> Stephan Szabo <sszabo@megazone.bigpanda.com> writes:
>
> > On Fri, 2 Sep 2005, [ISO-8859-2] Graf László wrote:
>
> >>
> >> CREATE FUNCTION test_verif() RETURNS trigger AS $test_verif$
> >> BEGIN
> >> NEW.id := select nextval('test_azon_seq');
>
> > I think you want to remove select here, you're already effectively doing a
> > select of the right hand side in the assignment.
>
> >> NEW.nev := nev;
> > I think you want to remove this line entirely. What nev were you
> > expecting on the right hand side? If it's the new one, well, NEW.new is
> > already that.
>
> László could also remove the entire trigger and use something like
>
>
> CREATE TABLE test (
> id SERIAL NOT NULL,
> nev VARCHAR(25),
> datum TIMESTAMP NOT NULL DEFAULT current_timestamp,
> PRIMARY KEY (id)
> );
That's slightly different though. The trigger forces the value whether or
not a value was assigned in the insert, the defaults only apply if the
column does not have a value given to it.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2005-09-06 14:00 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-09-02 07:26 ERROR: syntax error at or near "select" at character 9 Graf László <graf.laszlo@axis.hu>
2005-09-06 04:35 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2005-09-06 08:57 ` Harald Fuchs <hf0614x@protecting.net>
2005-09-06 14:00 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
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