4

Using the dbeaver tool, I want to check a script for syntax errors without actually running it.

Purpose: For a long insert query (postgresql syntax, PostgreSQL 10.15) in the form of:

INSERT INTO schema1.table1
(t1_id, fk1_id, fk_2_id, col1, col2)
  VALUES
           (nextval('schema1.sq_table1'), fk1_id_1, fk1_id_2,col1_val_1, col1_val_2),
            -- etc, literally thousands of lines

I cannot run the prod-version of the query in a not-prod region, because the foreign keys are different.

So is there a way to just check the SQL's syntax without running it. It throws foreign key constraint errors in the not-prod region, so I think that verifies the syntax, but I'd like to be doubly sure.

As per comment below, I think for the case here (insert with foreign-key), a foreign-key-violation-error would verify the syntax, but there is still the general case: Is it possible to verify the syntax of the SQL query without actually running it? I would think that there are probably several cases that this would be useful.

JosephDoggie
  • 203
  • 3
  • 10

1 Answers1

4

If you explain your query it is compiled but not executed. This means that it is checked for syntactic errors, but constraints are not validated against your data.

Lennart - Slava Ukraini
  • 23,842
  • 3
  • 34
  • 72