Re: open and close columns in the NEW record not allowed - Mailing list pgsql-hackers

From Adrian Klaver
Subject Re: open and close columns in the NEW record not allowed
Date
Msg-id 52F3A60F.9010606@gmail.com
Whole thread Raw
In response to open and close columns in the NEW record not allowed  (Rafael Martinez Guerrero <r.m.guerrero@usit.uio.no>)
Responses Re: open and close columns in the NEW record not allowed  (Rafael Martinez Guerrero <r.m.guerrero@usit.uio.no>)
List pgsql-hackers
On 02/06/2014 06:35 AM, Rafael Martinez Guerrero wrote:
> Hello
>
> One of our users is having a problem with a trigger in a system running
> postgresql 9.3.
>
> The problem is that pl/pgsql does not accept open and close as column
> names when used in the NEW record in a trigger function.
>
> This page:
> http://www.postgresql.org/docs/9.3/static/sql-keywords-appendix.html
> does not say that they are reserved words in postgresql (although they
> are reserved words in the sql standard)
>
> In the other hand, postgres allows to create and update tables with
> columns named open/close without problems.
>
> We think the behavior should be consistent, either it is allow to use
> them or not, but not like it is today.
>

The catch all from here:

http://www.postgresql.org/docs/9.3/interactive/sql-keywords-appendix.html

is:

" As a general rule, if you get spurious parser errors for commands that 
contain any of the listed key words as an identifier you should try to 
quote the identifier to see if the problem goes away."


Which indeed solves the problem on my end at least:

test=> CREATE OR REPLACE FUNCTION public.test_open() RETURNS trigger LANGUAGE plpgsql
AS $function$
BEGIN INSERT INTO test_open_trigger (id, open) VALUES (NEW.id, NEW."open"); RETURN NEW;
END;
$function$
;

test=> \d test_open             Table "public.test_open" Column |            Type             | Modifiers
--------+-----------------------------+----------- id     | integer                     | open   | timestamp without
timezone |
 
Triggers:    test_open AFTER INSERT ON test_open FOR EACH ROW EXECUTE PROCEDURE 
test_open()

test=> INSERT INTO test_open (id,open) VALUES (1,now());
INSERT 0 1


>
> Thanks in advance.
>
> regards,
>


-- 
Adrian Klaver
adrian.klaver@gmail.com



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Row-security on updatable s.b. views
Next
From: Tom Lane
Date:
Subject: Re: open and close columns in the NEW record not allowed