pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Multi-row insert: error at terminal row.
17+ messages / 6 participants
[nested] [flat]

* Multi-row insert: error at terminal row.
@ 2020-10-29 15:43  Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 2 replies; 17+ messages in thread

From: Rich Shepard @ 2020-10-29 15:43 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

I'm loading data into tables with the 'insert' statement. There are many
rows containing values and each is bracketed by parentheses except for the
last row. That's terminated with a semicolon, but psql reports an error
there:

psql:organizations.sql:1926: ERROR:  syntax error at or near ";"
LINE 1925: ...m',null,'Port','Opportunity',null);
                                                 ^
I'm not seeing why that's an error. All previous rows terminate with a comma
and I don't know where else to look for the reason. What am I missing
seeing?

TIA,

Rich






^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 15:45  Rob Sargent <robjsargent@gmail.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 1 reply; 17+ messages in thread

From: Rob Sargent @ 2020-10-29 15:45 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org



On 10/29/20 9:43 AM, Rich Shepard wrote:
> I'm loading data into tables with the 'insert' statement. There are many
> rows containing values and each is bracketed by parentheses except for the
> last row. That's terminated with a semicolon, but psql reports an error
> there:
> 
> psql:organizations.sql:1926: ERROR:  syntax error at or near ";"
> LINE 1925: ...m',null,'Port','Opportunity',null);
>                                                  ^
> I'm not seeing why that's an error. All previous rows terminate with a 
> comma
> and I don't know where else to look for the reason. What am I missing
> seeing?
> 
> TIA,
> 
> Rich
> 
> 
> 

Can we see the last two line of the file (1924, 1925)?





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 15:52  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 0 replies; 17+ messages in thread

From: Tom Lane @ 2020-10-29 15:52 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: pgsql-general@lists.postgresql.org

Rich Shepard <rshepard@appl-ecosys.com> writes:
> I'm loading data into tables with the 'insert' statement. There are many
> rows containing values and each is bracketed by parentheses except for the
> last row. That's terminated with a semicolon, but psql reports an error
> there:

> psql:organizations.sql:1926: ERROR:  syntax error at or near ";"
> LINE 1925: ...m',null,'Port','Opportunity',null);
>                                                  ^
> I'm not seeing why that's an error. All previous rows terminate with a comma
> and I don't know where else to look for the reason. What am I missing
> seeing?

First thought is that you might need another right parenthesis there.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 15:58  Rich Shepard <rshepard@appl-ecosys.com>
  parent: Rob Sargent <robjsargent@gmail.com>
  0 siblings, 1 reply; 17+ messages in thread

From: Rich Shepard @ 2020-10-29 15:58 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Thu, 29 Oct 2020, Rob Sargent wrote:

> Can we see the last two line of the file (1924, 1925)?

Rob,

(2697,'Port of Newport','http://www.portofnewport.com',null,'Port','Opportunity',null),
(2698,'Port of Portland','http://www.portofportland.com',null,'Port','Opportunity',null);

Each line is enclosed in parentheses and is terminated with a comma.

Regards,

Rich





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:04  Paul Förster <paul.foerster@gmail.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 1 reply; 17+ messages in thread

From: Paul Förster @ 2020-10-29 16:04 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>

Hi Rich,

> On 29. Oct, 2020, at 16:58, Rich Shepard <rshepard@appl-ecosys.com> wrote:
> 
> On Thu, 29 Oct 2020, Rob Sargent wrote:
> 
>> Can we see the last two line of the file (1924, 1925)?
> 
> Rob,
> 
> (2697,'Port of Newport','http://www.portofnewport.com',null,'Port','Opportunity',null),
> (2698,'Port of Portland','http://www.portofportland.com',null,'Port','Opportunity',null);
> 
> Each line is enclosed in parentheses and is terminated with a comma.

the last line has a closing parenthesis missing.

Cheers,
Paul




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:08  Rich Shepard <rshepard@appl-ecosys.com>
  parent: Paul Förster <paul.foerster@gmail.com>
  0 siblings, 2 replies; 17+ messages in thread

From: Rich Shepard @ 2020-10-29 16:08 UTC (permalink / raw)
  To: PostgreSQL General <pgsql-general@lists.postgresql.org>

On Thu, 29 Oct 2020, Paul Förster wrote:

>> (2698,'Port of Portland','http://www.portofportland.com',null,'Port','Opportunity',null);
> the last line has a closing parenthesis missing.

Paul,

I see a closing parenthesis immediately in front of the semi-colon and emacs
shows it matches the opening parenthesis.

Rich





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:15  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 0 replies; 17+ messages in thread

From: Adrian Klaver @ 2020-10-29 16:15 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; PostgreSQL General <pgsql-general@lists.postgresql.org>

On 10/29/20 9:08 AM, Rich Shepard wrote:
> On Thu, 29 Oct 2020, Paul Förster wrote:
> 
>>> (2698,'Port of 
>>> Portland','http://www.portofportland.com',null,'Port','Opportunity',null); 
>>>
>> the last line has a closing parenthesis missing.
> 
> Paul,
> 
> I see a closing parenthesis immediately in front of the semi-colon and 
> emacs
> shows it matches the opening parenthesis.

Pretty sure the thinking is that the opening parenthesis is further 
upstream, say around VALUES?

> 
> Rich
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:15  Paul Förster <paul.foerster@gmail.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 2 replies; 17+ messages in thread

From: Paul Förster @ 2020-10-29 16:15 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>

Hi Rich,

> On 29. Oct, 2020, at 17:08, Rich Shepard <rshepard@appl-ecosys.com> wrote:
> 
> On Thu, 29 Oct 2020, Paul Förster wrote:
> 
>>> (2698,'Port of Portland','http://www.portofportland.com',null,'Port','Opportunity',null);
>> the last line has a closing parenthesis missing.
> 
> Paul,
> 
> I see a closing parenthesis immediately in front of the semi-colon and emacs
> shows it matches the opening parenthesis.

I don't know Emacs, I'm a vi guy. ;-)

But I guess that Emacs shows the matching closing bracket at the beginning of the line, which matches that single tuple. But you also need a closing bracket for the set of tuples like this:

insert ...
(
    (v1, v2, v3),
    (v4, v5, v6),
    (v7, v8, v9)    <= this is the bracket pair that Emacs shows as matching.
);     <= this is the missing bracket.

Cheers,
Paul




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:21  David G. Johnston <david.g.johnston@gmail.com>
  parent: Paul Förster <paul.foerster@gmail.com>
  1 sibling, 2 replies; 17+ messages in thread

From: David G. Johnston @ 2020-10-29 16:21 UTC (permalink / raw)
  To: Paul Förster <paul.foerster@gmail.com>; +Cc: Rich Shepard <rshepard@appl-ecosys.com>; PostgreSQL General <pgsql-general@lists.postgresql.org>

On Thu, Oct 29, 2020 at 9:16 AM Paul Förster <paul.foerster@gmail.com>
wrote:

> But I guess that Emacs shows the matching closing bracket at the beginning
> of the line, which matches that single tuple. But you also need a closing
> bracket for the set of tuples like this:
>
> insert ...
> (
>     (v1, v2, v3),
>     (v4, v5, v6),
>     (v7, v8, v9)    <= this is the bracket pair that Emacs shows as
> matching.
> );     <= this is the missing bracket.
>
>
Except that isn't valid INSERT statement syntax.  You are missing "values"
and there is no enclosing parens:

INSERT INTO tbl (i) VALUES (1), (2), (3); --this is perfectly valid

That said seeing the first few rows, in addition to the last few, would
help.

David J.

^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:31  Paul Förster <paul.foerster@gmail.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 17+ messages in thread

From: Paul Förster @ 2020-10-29 16:31 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Rich Shepard <rshepard@appl-ecosys.com>; PostgreSQL General <pgsql-general@lists.postgresql.org>

Hi David,

> On 29. Oct, 2020, at 17:21, David G. Johnston <david.g.johnston@gmail.com> wrote:
> 
> On Thu, Oct 29, 2020 at 9:16 AM Paul Förster <paul.foerster@gmail.com> wrote:
> But I guess that Emacs shows the matching closing bracket at the beginning of the line, which matches that single tuple. But you also need a closing bracket for the set of tuples like this:
> 
> insert ...
> (
>     (v1, v2, v3),
>     (v4, v5, v6),
>     (v7, v8, v9)    <= this is the bracket pair that Emacs shows as matching.
> );     <= this is the missing bracket.
> 
> 
> Except that isn't valid INSERT statement syntax.  You are missing "values" and there is no enclosing parens:
> 
> INSERT INTO tbl (i) VALUES (1), (2), (3); --this is perfectly valid
> 
> That said seeing the first few rows, in addition to the last few, would help.

sorry, I didn't check. My point was that there is a mismatch between a closing parent and an initial opening parent somewhere even if Emacs shows the last parent as matching the last opening parent.

So, you are right of course.

postgres=# create table t1(v1 int, v2 int, v3 int);
CREATE TABLE
postgres=# insert into t1(v1, v2, v3)
values
    (1, 2, 3),
    (4, 5, 6),
    (7, 8, 9);
INSERT 0 3

Cheers,
Paul




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:35  Rich Shepard <rshepard@appl-ecosys.com>
  parent: Paul Förster <paul.foerster@gmail.com>
  1 sibling, 1 reply; 17+ messages in thread

From: Rich Shepard @ 2020-10-29 16:35 UTC (permalink / raw)
  To: PostgreSQL General <pgsql-general@lists.postgresql.org>

On Thu, 29 Oct 2020, Paul Förster wrote:

> insert ...
> (
>    (v1, v2, v3),
>    (v4, v5, v6),
>    (v7, v8, v9)    <= this is the bracket pair that Emacs shows as matching.
> );     <= this is the missing bracket.

Paul/Adrian/Tom:

First thing I did was look at the postgres 12 manual. On page 155 I see:

You can insert multiple rows in a single command:
INSERT INTO products (product_no, name, price) VALUES
     (1, 'Cheese', 9.99),
     (2, 'Bread', 1.99),
     (3, 'Milk', 2.99);

Which is what I have. There are no extra parentheses enclosing multiple rows
of VALUES. But, adding them makes no difference: same error reported.

Thanks,

Rich





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:37  Rich Shepard <rshepard@appl-ecosys.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 1 reply; 17+ messages in thread

From: Rich Shepard @ 2020-10-29 16:37 UTC (permalink / raw)
  To: PostgreSQL General <pgsql-general@lists.postgresql.org>

On Thu, 29 Oct 2020, David G. Johnston wrote:

> That said seeing the first few rows, in addition to the last few, would
> help.

David,

insert into organizations (org_nbr,org_name,org_url,org_email,industry,status,comment) values 
(1,'Tidewater Contractors Inc',null,null,'Mining','Opportunity','GEN12A'),
(2,'All Rock LLC','www.allrockllc.com',null,'Mining','Opportunity','GEN12A'),
...

Thanks,

Rich







^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:39  David G. Johnston <david.g.johnston@gmail.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 1 reply; 17+ messages in thread

From: David G. Johnston @ 2020-10-29 16:39 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>

On Thu, Oct 29, 2020 at 9:37 AM Rich Shepard <rshepard@appl-ecosys.com>
wrote:

> On Thu, 29 Oct 2020, David G. Johnston wrote:
>
> > That said seeing the first few rows, in addition to the last few, would
> > help.
>
> David,
>
> insert into organizations
> (org_nbr,org_name,org_url,org_email,industry,status,comment) values
> (1,'Tidewater Contractors Inc',null,null,'Mining','Opportunity','GEN12A'),
> (2,'All Rock LLC','www.allrockllc.com
> ',null,'Mining','Opportunity','GEN12A'),
> ...
>
>
As your general syntax seems correct I would suspect an issue in the data
values - like having a single quote in an organization name that isn't
properly escaped (doubled).  I'd first make sure insert one record works
then begin bisecting your values, only inserting subsets at a time, until
you narrow down the offending record.

David J.

^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:45  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 1 reply; 17+ messages in thread

From: Adrian Klaver @ 2020-10-29 16:45 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; PostgreSQL General <pgsql-general@lists.postgresql.org>

On 10/29/20 9:35 AM, Rich Shepard wrote:
> On Thu, 29 Oct 2020, Paul Förster wrote:
> 
>> insert ...
>> (
>>    (v1, v2, v3),
>>    (v4, v5, v6),
>>    (v7, v8, v9)    <= this is the bracket pair that Emacs shows as 
>> matching.
>> );     <= this is the missing bracket.
> 
> Paul/Adrian/Tom:
> 
> First thing I did was look at the postgres 12 manual. On page 155 I see:
> 
> You can insert multiple rows in a single command:
> INSERT INTO products (product_no, name, price) VALUES
>      (1, 'Cheese', 9.99),
>      (2, 'Bread', 1.99),
>      (3, 'Milk', 2.99);
> 
> Which is what I have. There are no extra parentheses enclosing multiple 
> rows
> of VALUES. But, adding them makes no difference: same error reported.

If you did something like:

INSERT INTO products (product_no, name, price) VALUES
     (
     (1, 'Cheese', 9.99),
     (2, 'Bread', 1.99),
     (3, 'Milk', 2.99)
);

then you should have gotten a different error. Something like:

ERROR:  column "product_no" is of type integer but expression is of type 
record

I'm going to say the issue is more like what David posted, an escaping 
problem in the data. Not sure how many rows you are dealing with, but it 
might be helpful to break them down into smaller batches to isolate the 
problem.


> 
> Thanks,
> 
> Rich
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:58  Rich Shepard <rshepard@appl-ecosys.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 17+ messages in thread

From: Rich Shepard @ 2020-10-29 16:58 UTC (permalink / raw)
  To: PostgreSQL General <pgsql-general@lists.postgresql.org>

On Thu, 29 Oct 2020, David G. Johnston wrote:

> As your general syntax seems correct I would suspect an issue in the data
> values - like having a single quote in an organization name that isn't
> properly escaped (doubled). I'd first make sure insert one record works
> then begin bisecting your values, only inserting subsets at a time, until
> you narrow down the offending record.

David,

I checked and repaired all single apostrophe's with doubled apostrophies.
Postgres found other syntax errors (period rather than comma; missing comma)
but didn't reject single quotes as apostrophes within a string. Also, there
are no strings in this table that would have apostrophes.

Thanks,

Rich





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 16:59  Rich Shepard <rshepard@appl-ecosys.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 17+ messages in thread

From: Rich Shepard @ 2020-10-29 16:59 UTC (permalink / raw)
  To: PostgreSQL General <pgsql-general@lists.postgresql.org>

On Thu, 29 Oct 2020, Adrian Klaver wrote:

> INSERT INTO products (product_no, name, price) VALUES
>    (
>    (1, 'Cheese', 9.99),
>    (2, 'Bread', 1.99),
>    (3, 'Milk', 2.99)
> );
>
> then you should have gotten a different error. Something like:
>
> ERROR:  column "product_no" is of type integer but expression is of type 
> record

Adrian,

Tried that but the error was the same: the closing semi-colon.

> I'm going to say the issue is more like what David posted, an escaping
> problem in the data. Not sure how many rows you are dealing with, but it
> might be helpful to break them down into smaller batches to isolate the
> problem.

Yep, that's what I'll do.

Thanks,

Rich





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Multi-row insert: error at terminal row.
@ 2020-10-29 17:04  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 0 replies; 17+ messages in thread

From: Adrian Klaver @ 2020-10-29 17:04 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; PostgreSQL General <pgsql-general@lists.postgresql.org>

On 10/29/20 9:59 AM, Rich Shepard wrote:
> On Thu, 29 Oct 2020, Adrian Klaver wrote:
> 
>> INSERT INTO products (product_no, name, price) VALUES
>>    (
>>    (1, 'Cheese', 9.99),
>>    (2, 'Bread', 1.99),
>>    (3, 'Milk', 2.99)
>> );
>>
>> then you should have gotten a different error. Something like:
>>
>> ERROR:  column "product_no" is of type integer but expression is of 
>> type record
> 
> Adrian,
> 
> Tried that but the error was the same: the closing semi-colon.

It should not have been the same, so there is something else amiss.

> 
>> I'm going to say the issue is more like what David posted, an escaping
>> problem in the data. Not sure how many rows you are dealing with, but it
>> might be helpful to break them down into smaller batches to isolate the
>> problem.
> 
> Yep, that's what I'll do.
> 
> Thanks,
> 
> Rich
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 17+ messages in thread


end of thread, other threads:[~2020-10-29 17:04 UTC | newest]

Thread overview: 17+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 15:43 Multi-row insert: error at terminal row. Rich Shepard <rshepard@appl-ecosys.com>
2020-10-29 15:45 ` Rob Sargent <robjsargent@gmail.com>
2020-10-29 15:58   ` Rich Shepard <rshepard@appl-ecosys.com>
2020-10-29 16:04     ` Paul Förster <paul.foerster@gmail.com>
2020-10-29 16:08       ` Rich Shepard <rshepard@appl-ecosys.com>
2020-10-29 16:15         ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-10-29 16:15         ` Paul Förster <paul.foerster@gmail.com>
2020-10-29 16:21           ` David G. Johnston <david.g.johnston@gmail.com>
2020-10-29 16:31             ` Paul Förster <paul.foerster@gmail.com>
2020-10-29 16:37             ` Rich Shepard <rshepard@appl-ecosys.com>
2020-10-29 16:39               ` David G. Johnston <david.g.johnston@gmail.com>
2020-10-29 16:58                 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-10-29 16:35           ` Rich Shepard <rshepard@appl-ecosys.com>
2020-10-29 16:45             ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-10-29 16:59               ` Rich Shepard <rshepard@appl-ecosys.com>
2020-10-29 17:04                 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-10-29 15:52 ` Tom Lane <tgl@sss.pgh.pa.us>

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