![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
10:06:21.08586.03.0001. query: BEGIN .08586.03.0001.INSERT INTO config (name, value) VALUES (E'dbexp', E'10'); .08586.03.0001.EXCEPTION WHEN unique_violation THEN .08586.03.0001.UPDATE config SET value=E'10' WHERE name=E'dbexp'; .08586.03.0001.END error: fatal query: ERROR: syntax error at or near "INSERT" .08586.03.0001.LINE 2: INSERT INTO config (name, value) VALUES (E'dbexp', E'10'); .08586.03.0001. ^ 10:10:01.09104.03.0001. query: BEGIN; .09104.03.0001.INSERT INTO config (name, value) VALUES (E'dbexp', E'10'); .09104.03.0001.EXCEPTION WHEN unique_violation THEN .09104.03.0001.UPDATE config SET value=E'10' WHERE name=E'dbexp'; .09104.03.0001.END error: fatal query: ERROR: syntax error at or near "EXCEPTION" .09104.03.0001.LINE 3: EXCEPTION WHEN unique_violation THEN .09104.03.0001. ^ At least Postgres retains its ideological purity by avoiding that terrible REPLACE command everyone else uses. |
#2
| |||
| |||
|
|
Everyone else who? |
|
You might want to have a look at the MERGE statement which where introduced in SQL2003 and is supported by at least PostgreSQL, Oracle, DB2 and SQL server. |
#3
| |||
| |||
|
|
Unfortunately MERGE is *not* supported by PostgreSQL... |
#4
| |||
| |||
|
|
10:06:21.08586.03.0001. query: BEGIN .08586.03.0001.INSERT INTO config (name, value) VALUES (E'dbexp', E'10'); .08586.03.0001.EXCEPTION WHEN unique_violation THEN .08586.03.0001.UPDATE config SET value=E'10' WHERE name=E'dbexp'; .08586.03.0001.END error: fatal query: ERROR: syntax error at or near "INSERT" .08586.03.0001.LINE 2: INSERT INTO config (name, value) VALUES (E'dbexp', E'10'); .08586.03.0001. ^ 10:10:01.09104.03.0001. query: BEGIN; .09104.03.0001.INSERT INTO config (name, value) VALUES (E'dbexp', E'10'); .09104.03.0001.EXCEPTION WHEN unique_violation THEN .09104.03.0001.UPDATE config SET value=E'10' WHERE name=E'dbexp'; .09104.03.0001.END error: fatal query: ERROR: syntax error at or near "EXCEPTION" .09104.03.0001.LINE 3: EXCEPTION WHEN unique_violation THEN .09104.03.0001. ^ At least Postgres retains its ideological purity by avoiding that terrible REPLACE command everyone else uses. I note that you don't explain why the example reduced from Postgres documentation gets a syntax error. http://www.postgresql.org/docs/9.0/s...ERROR-TRAPPING |
#5
| |||
| |||
|
|
Matthew Woodcraft <mattheww (AT) chiark (DOT) greenend.org.uk> wrote: In your second block, I think perhaps you're trying to use the example from the PL/pgSQL documentation in direct SQL input. If that's what's going on, you ought to be able to get it to work by wrapping your queries up in a DO statement: http://www.postgresql.org/docs/9.0/static/sql-do.html 20:59:45.12147.03.0001. query: DO .12147.03.0001.BEGIN; .12147.03.0001.INSERT INTO config (name, value) VALUES (E'dbexp', E'10'); .12147.03.0001.EXCEPTION WHEN unique_violation THEN .12147.03.0001.UPDATE config SET value=E'10' WHERE name=E'dbexp'; .12147.03.0001.END error: fatal query: ERROR: syntax error at or near "DO" .12147.03.0001.LINE 1: DO .12147.03.0001. ^ 21:02:57.12672.03.0001. query: DO; .12672.03.0001.BEGIN; .12672.03.0001.INSERT INTO config (name, value) VALUES (E'dbexp', E'10'); .12672.03.0001.EXCEPTION WHEN unique_violation THEN .12672.03.0001.UPDATE config SET value=E'10' WHERE name=E'dbexp'; .12672.03.0001.END error: fatal query: ERROR: syntax error at or near "DO" .12672.03.0001.LINE 1: DO; .12672.03.0001. ^ ERROR: syntax error at or near "DO" at character 1 |
![]() |
| Thread Tools | |
| Display Modes | |
| |