Thread: Does PostgreSQL support Dynamic SQL?

Does PostgreSQL support Dynamic SQL?

From
"Lark"
Date:
Hi all!
2 questions:
Does PostgreSQL support dynamic SQL, if so, when can i see any documents on
it at PostgreSQL.org?
thank's :)



Re: Does PostgreSQL support Dynamic SQL?

From
The Hermit Hacker
Date:
Stupid question, but what is Dynamic SQL? :)


On Sun, 14 Jan 2001, Lark wrote:

> Hi all!
> 2 questions:
> Does PostgreSQL support dynamic SQL, if so, when can i see any documents on
> it at PostgreSQL.org?
> thank's :)
>
>
>

Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
Systems Administrator @ hub.org
primary: scrappy@hub.org           secondary: scrappy@{freebsd|postgresql}.org


RE: Does PostgreSQL support Dynamic SQL?

From
Mike Mascari
Date:
Its an extension to the embedded SQL preprocessor which allows you to
dynamically build queries at run-time, instead of compile-time. So instead
of having to declare the variables associated with query results at
comile-time, like:

EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR userid[30];
    VARCHAR password[30];
    VARCHAR employee[30];
    ...
EXEC SQL END DECLARE SECTION;
EXEC SQL INCLUDE SQLCA;

and later performing a SELECT statement already defined in the C code like:

EXEC SQL SELECT employeeid
    INTO :employee
    FROM employees;

you can *dynamically* build a SELECT statement, ask the database for a
description of the result sets' attributes, allocate the variables
dynamically to hold the results, and then perform the FETCH.
According to the man page for ecpg with version 7, there currently isn't
support for the PREPARE statement, which is a prerequisite (along with
DESCRIBE) for dynamic SQL queries. Perhaps Michael Meskes might be able to
shed some more light on the status...

Hope that helps,

Mike Mascari
mascarm@mascari.com

-----Original Message-----
From:    The Hermit Hacker [SMTP:scrappy@hub.org]

Stupid question, but what is Dynamic SQL? :)


On Sun, 14 Jan 2001, Lark wrote:

> Hi all!
> 2 questions:
> Does PostgreSQL support dynamic SQL, if so, when can i see any documents
on
> it at PostgreSQL.org?
> thank's :)
>
>
>

Marc G. Fournier                   ICQ#7615664               IRC Nick:
Scrappy
Systems Administrator @ hub.org
primary: scrappy@hub.org           secondary:
scrappy@{freebsd|postgresql}.org


Re: Does PostgreSQL support Dynamic SQL?

From
Tom Lane
Date:
Mike Mascari <mascarm@mascari.com> writes:
> Its an extension to the embedded SQL preprocessor which allows you to
> dynamically build queries at run-time, instead of compile-time.
> [...]
> you can *dynamically* build a SELECT statement, ask the database for a
> description of the result sets' attributes, allocate the variables
> dynamically to hold the results, and then perform the FETCH.

Well, this is obviously trivial if you use libpq directly.  I don't
know whether ecpg emulates the spec's idea of the right API for it,
however.

            regards, tom lane