Re: Is this legal SQL? Is it a good practice? - Mailing list pgsql-general

From Bill Harper
Subject Re: Is this legal SQL? Is it a good practice?
Date
Msg-id 412BBE5C.6080404@solutionst.com
Whole thread Raw
In response to Is this legal SQL? Is it a good practice?  (Carlos Moreno <moreno@mochima.com>)
Responses Re: Is this legal SQL? Is it a good practice?  (Carlos Moreno <moreno@mochima.com>)
List pgsql-general
Carlos Moreno wrote:

> But I'm wondering -- is this a PostgreSQL extension,
> or is it "legal SQL"?

This is a reasonably standard result from an "exec" or "execute" call,
but I am not an SQL expert.  How else could the psql command
line utility process command files?

> What happens if the first command is ok but the second
> one fails?

I've not used this interface extensively because I do
mostly transactional work. The easy way to test would be to
make the second statement fail on a syntax error.

> Any reason why this should be avoided?

Yes. You've raised the core issue in your question about what happens
when a command fails.  For efficiency and convenience, use prepared
statements.
For greater efficiency, execute stored procedures to do your work

In general, my web applications use prepared statements for moderate
efficiency.
For batch applications, I would use stored procedures or embedded SQL (both
provide the advantage of stored, optimized query plans).

-bill

pgsql-general by date:

Previous
From: "Gavin M. Roy"
Date:
Subject: Re: Gentoo for production DB server?
Next
From: Greg Stark
Date:
Subject: Deadlocks caused by referential integrity checks