pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedsyntax issue with insert statement
3+ messages / 3 participants
[nested] [flat]
* syntax issue with insert statement
@ 2005-01-13 17:17 David Bear <David.Bear@asu.edu>
0 siblings, 2 replies; 3+ messages in thread
From: David Bear @ 2005-01-13 17:17 UTC (permalink / raw)
To: pgsql-admin
I'm in process of migrating data. That means lots of data munging.
I decided that while I'm coding I should go ahead and create sql syntax rather
than just some delimited file. So I produced the following code:
docflow=> INSERT INTO student (first_name, last_name, middle_name, added_by,
affiliate_id, added_on) VALUES (John, Doe, -, '{john}', 484848484, 02/02/20);
ERROR: syntax error at or near "," at character 112
I could not get the INSERT statement to work using the column name VALUES
syntax.
So, then I tried:
docflow=> INSERT INTO student VALUES (29394959, David, Doe, _, 09/09/99, '{test}')
That worked.
I though I might have quoting issue, but I'm sticking with lower case
identifiers.
This seems like such a trivial question, but I just cant see where I went
wrong. Maybe I've stared at it too long. Please advise.
--
David Bear
phone: 480-965-8257
fax: 480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
"Beware the IP portfolio, everyone will be suspect of trespassing"
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: syntax issue with insert statement
@ 2005-01-13 18:45 Scott Marlowe <smarlowe@g2switchworks.com>
parent: David Bear <David.Bear@asu.edu>
1 sibling, 0 replies; 3+ messages in thread
From: Scott Marlowe @ 2005-01-13 18:45 UTC (permalink / raw)
To: David.Bear@asu.edu; +Cc: pgsql-admin
On Thu, 2005-01-13 at 11:17, David Bear wrote:
> I'm in process of migrating data. That means lots of data munging.
>
> I decided that while I'm coding I should go ahead and create sql syntax rather
> than just some delimited file. So I produced the following code:
>
> docflow=> INSERT INTO student (first_name, last_name, middle_name, added_by,
> affiliate_id, added_on) VALUES (John, Doe, -, '{john}', 484848484, 02/02/20);
>
> ERROR: syntax error at or near "," at character 112
>
>
> I could not get the INSERT statement to work using the column name VALUES
> syntax.
>
> So, then I tried:
>
> docflow=> INSERT INTO student VALUES (29394959, David, Doe, _, 09/09/99, '{test}')
>
> That worked.
>
> I though I might have quoting issue, but I'm sticking with lower case
> identifiers.
>
> This seems like such a trivial question, but I just cant see where I went
> wrong. Maybe I've stared at it too long. Please advise.
Text strings and dates need to be surrounded by single quotes, so your
1st insert should look like:
INSERT INTO student (first_name, last_name, middle_name, added_by,
affiliate_id, added_on)
VALUES ('John', 'Doe', '-', '{john}', 484848484, '02/02/20');
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: syntax issue with insert statement
@ 2005-01-13 18:51 Michael Fuhr <mike@fuhr.org>
parent: David Bear <David.Bear@asu.edu>
1 sibling, 0 replies; 3+ messages in thread
From: Michael Fuhr @ 2005-01-13 18:51 UTC (permalink / raw)
To: David Bear <David.Bear@asu.edu>; +Cc: pgsql-admin
On Thu, Jan 13, 2005 at 10:17:47AM -0700, David Bear wrote:
> I'm in process of migrating data. That means lots of data munging.
>
> I decided that while I'm coding I should go ahead and create sql syntax rather
> than just some delimited file.
If you have a lot of data to load, then using COPY with a delimited
file will be faster than a series of INSERTs.
> So I produced the following code:
>
> docflow=> INSERT INTO student (first_name, last_name, middle_name, added_by,
> affiliate_id, added_on) VALUES (John, Doe, -, '{john}', 484848484, 02/02/20);
>
> ERROR: syntax error at or near "," at character 112
You should be quoting the non-numeric values:
INSERT INTO student (first_name, last_name, middle_name, added_by,
affiliate_id, added_on)
VALUES ('John', 'Doe', '-', '{john}', 484848484, '02/02/20');
> So, then I tried:
>
> docflow=> INSERT INTO student VALUES (29394959, David, Doe, _, 09/09/99, '{test}')
>
> That worked.
That's surprising -- what version of PostgreSQL are you using? Is
something preprocessing your statements before sending them to the
backend? The non-numeric values should be quoted; failure to do
so should result in errors like 'column "david" does not exist'.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-01-13 18:51 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-13 17:17 syntax issue with insert statement David Bear <David.Bear@asu.edu>
2005-01-13 18:45 ` Scott Marlowe <smarlowe@g2switchworks.com>
2005-01-13 18:51 ` Michael Fuhr <mike@fuhr.org>
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