Recent

Author Topic: Executing PostgreSQL script  (Read 1105 times)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1315
Executing PostgreSQL script
« on: June 14, 2023, 01:44:14 pm »
I'm trying to run a script like this:

Code: SQL  [Select][+][-]
  1. DO
  2. $do$
  3. BEGIN
  4.    IF EXISTS (SELECT FROM orders) THEN
  5.       DELETE FROM orders;
  6.    ELSE
  7.       INSERT INTO orders VALUES (1,2,3);
  8.    END IF;
  9. END
  10. $do$

It doesn't matter if I try to execute this with a TSQLQuery or TSQLScript, I always get this error:

Code: Text  [Select][+][-]
  1. Primary Error: unterminated dollar-quoted string at or near "$do$

In pgAdmin it works as expected.

gsa

  • New Member
  • *
  • Posts: 11
Re: Executing PostgreSQL script
« Reply #1 on: June 14, 2023, 02:48:48 pm »

It doesn't matter if I try to execute this with a TSQLQuery or TSQLScript, I always get this error:

Code: Text  [Select][+][-]
  1. Primary Error: unterminated dollar-quoted string at or near "$do$

In pgAdmin it works as expected.

Using TSQLScript you should set the folowing properties:

      UseDollarString := True;
      DollarStrings.Add('$$'); 

Gerd

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1315
Re: Executing PostgreSQL script
« Reply #2 on: June 14, 2023, 03:26:14 pm »
Ah, thanks. I had replaced the "$do$" with a single quote and doubled up all the other ones, but that makes a mess of it.

gucao

  • New Member
  • *
  • Posts: 37
Re: Executing PostgreSQL script
« Reply #3 on: June 15, 2023, 03:57:29 am »
uses tsqlquery is ok.
test with lazarus 2.2.0.
Please give me more patience with my poor English

 

TinyPortal © 2005-2018