Command to execute SQL string

Started by Łukasz Jarychabout 8 years ago4 messagesgeneral
Jump to latest
#1Łukasz Jarych
jaryszek@gmail.com

Hello,

i have a table when i have string in each row,
for example "DELETE FROM t_test WHERE ID = 3".

I want to execute for each row this command.
It is possible?

Best wishes,
Jacek

#2Francisco Olarte
folarte@peoplecall.com
In reply to: Łukasz Jarych (#1)
Re: Command to execute SQL string

Hello:

On Thu, Mar 8, 2018 at 1:26 PM, Łukasz Jarych <jaryszek@gmail.com> wrote:

i have a table when i have string in each row,
for example "DELETE FROM t_test WHERE ID = 3".

I want to execute for each row this command.
It is possible?

I supose you mean execute the command contained in each row. Anyway,
it is easy with a procedure, look for example at

https://www.postgresql.org/docs/10/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

just do a loop on your command table, follow the examples and you
should be done.

Francisco Olarte.

PS:

Jacek

Is this the same as Łukasz or Jarych ?

F.O.

#3Łukasz Jarych
jaryszek@gmail.com
In reply to: Francisco Olarte (#2)
Re: Command to execute SQL string

Hello Francisco,

thank you !

Jacek is the same as Łukasz. Is my second name and my artist's nickname ;-)

love your answer,
thank you!

Best,
Jacek

2018-03-08 13:40 GMT+01:00 Francisco Olarte <folarte@peoplecall.com>:

Show quoted text

Hello:

On Thu, Mar 8, 2018 at 1:26 PM, Łukasz Jarych <jaryszek@gmail.com> wrote:

i have a table when i have string in each row,
for example "DELETE FROM t_test WHERE ID = 3".

I want to execute for each row this command.
It is possible?

I supose you mean execute the command contained in each row. Anyway,
it is easy with a procedure, look for example at

https://www.postgresql.org/docs/10/static/plpgsql-statements.html#PLPGSQL-
STATEMENTS-EXECUTING-DYN

just do a loop on your command table, follow the examples and you
should be done.

Francisco Olarte.

PS:

Jacek

Is this the same as Łukasz or Jarych ?

F.O.

#4David G. Johnston
david.g.johnston@gmail.com
In reply to: Francisco Olarte (#2)
Re: Command to execute SQL string

On Thursday, March 8, 2018, Francisco Olarte <folarte@peoplecall.com> wrote:

On Thu, Mar 8, 2018 at 1:26 PM, Łukasz Jarych <jaryszek@gmail.com> wrote:

i have a table when i have string in each row,
for example "DELETE FROM t_test WHERE ID = 3".

I want to execute for each row this command.
It is possible?

I supose you mean execute the command contained in each row. Anyway,
it is easy with a procedure, look for example at

https://www.postgresql.org/docs/10/static/plpgsql-statements.html#PLPGSQL-
STATEMENTS-EXECUTING-DYN

See also v10 psql \gexec

David J.