0

I'm new to the world of PostgreSQL, but I'm old hat at PHP and MySQL.

I have a PHP script that creates and (should) execute queries to a PostgreSQL DB. The connection is fine, I can get data back with no problem, but my INSERT statement keeps failing. Here's a sample of one of the queries created by the script: (all info is a matter of public record, so this is real data)

INSERT INTO
leads_lead ( EIN, NAME, ICO, STREET, CITY, STATE, ZIP, GROUP, SUBSECTION, AFFILIATION, CLASSIFICATION, RULING, DEDUCTIBILITY, FOUNDATION, ACTIVITY, ORGANIZATION, STATUS, TAX_PERIOD, ASSET_CD, INCOME_CD, FILING_REQ_CD, PF_FILING_REQ_CD, ACCT_PD, ASSET_AMT, INCOME_AMT, REVENUE_AMT, NTEE_CD, SORT_NAME)
VALUES ('010520599','BLUE KNIGHTS MOTORCYCLE CLUB','% DOUGLAS LAMPLUGH','216 HEATHER LN','FAIRHOPE','AL','36532-7105','0000','10','3','1000','201402','2','00','000000000','5','01','201412','0','0','02','0','12','0','0','0','Y42','AL II');

The error I get back states:

ERROR:  syntax error at or near "GROUP"
LINE 1: ..._lead ( EIN, NAME, ICO, STREET, CITY, STATE, ZIP, GROUP, SUB...

This is returned in my console output, on a Ubuntu machine.

Any idea why this is failing? Trying to run this in the psql console give the same result, with a carat pointing at the 'G' in GROUP

I've also verified the spelling of the fields in my query matches the spelling (and case) of the fields in the database. I did NOT setup this database, but have full access to it.

1
  • 1
    GROUP is a keyword you have to escape it Commented Oct 1, 2015 at 13:09

1 Answer 1

2

You have to enclose GROUP in double quotes to stop it being interpreted as a keyword

INSERT INTO
leads_lead ( EIN, NAME, ICO, STREET, CITY, STATE, ZIP, "GROUP", SUBSECTION, AFFILIATION, CLASSIFICATION, RULING, DEDUCTIBILITY, FOUNDATION, ACTIVITY, ORGANIZATION, STATUS, TAX_PERIOD, ASSET_CD, INCOME_CD, FILING_REQ_CD, PF_FILING_REQ_CD, ACCT_PD, ASSET_AMT, INCOME_AMT, REVENUE_AMT, NTEE_CD, SORT_NAME)
VALUES ('010520599','BLUE KNIGHTS MOTORCYCLE CLUB','% DOUGLAS LAMPLUGH','216 HEATHER LN','FAIRHOPE','AL','36532-7105','0000','10','3','1000','201402','2','00','000000000','5','01','201412','0','0','02','0','12','0','0','0','Y42','AL II');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.