reserved word as a fieldname

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Uli
Posts: 1
Joined: Tue 11 Dec 2012 12:35

reserved word as a fieldname

Post by Uli » Thu 23 Apr 2020 13:24

Hello,

I have a table in which a field is called "offset". But since offset is a reserved word in PostGreSQL, I now have a problem when I want to assign a value to this field. In the debugger, I have the following picture before I want to post the record:

mMainQuery.Fields[0].Name 'id'
mMainQuery.Fields[0].Value 'TEST'
mMainQuery.Fields[1].Name 'remark'
mMainQuery.Fields[1].Value Null
mMainQuery.Fields[2].Name 'collection'
mMainQuery.Fields[2].Value Null
mMainQuery.Fields[3].Name 'time_field'
mMainQuery.Fields[3].Value Null
mMainQuery.Fields[4].Name 'offset'
mMainQuery.Fields[4].Value 300
mMainQuery.Fields[5].Name 'repeat_interval'
mMainQuery.Fields[5].Value Null
mMainQuery.Fields[6].Name 'stop_repeat_offset'
mMainQuery.Fields[6].Value Null
mMainQuery.Fields[7].Name 'repeat_on_field_change'
mMainQuery.Fields[7].Value False

My problem is the name of field 4 "offset". At the post I get this exception:
'syntax error at or near "offset"'

Can I set somewhere that the field names are put in single or double quotes? I cannot change the table.

wbr, Uli

oleg0k
Devart Team
Posts: 65
Joined: Wed 11 Mar 2020 08:28

Re: reserved word as a fieldname

Post by oleg0k » Fri 24 Apr 2020 09:28

Hello,
Since you are using the reserved word PostgreSQL, to solve the issue, please, set the TPgQuery.Options.QuoteNames property to True:

Code: Select all

mMainQuery.Options.QuoteNames:=True;
wbr, Oleg
Devart Team

Uli
Posts: 1
Joined: Tue 11 Dec 2012 12:35

Re: reserved word as a fieldname

Post by Uli » Mon 27 Apr 2020 07:36

Many, many thanks, that was the setting I had been looking for in vain

wbr, Uli

oleg0k
Devart Team
Posts: 65
Joined: Wed 11 Mar 2020 08:28

Re: reserved word as a fieldname

Post by oleg0k » Mon 27 Apr 2020 13:32

Hello,
Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.

wbr, Oleg
Devart Team

Post Reply