gset updated patch

Lists: pgsql-hackers
From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: gset updated patch
Date: 2012-11-03 18:45:36
Message-ID: CAFj8pRC5jDFbB0PrY0-yvSNraQWexrdx9CnDWJ5k__nYpJrAOA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

here is a updated patch

Regards

Pavel

Attachment Content-Type Size
gset_12.diff application/octet-stream 18.7 KB

From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-16 05:08:06
Message-ID: 1353042486.27898.3@mofo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 11/03/2012 01:45:36 PM, Pavel Stehule wrote:
> Hello
>
> here is a updated patch

This message does not appear to be threaded so I'm not
sure I've read the whole back-history. Also, I don't
really know what I'm doing. Never the less, I want
to try to contribute to somebody else's patch so
here's my comments. Make of them what you will.

I know there's been criticism for touching too many
different parts of the code, but writing your own
mini-lexical analyzer does not make sense to me.
There ought to be a clean way to move that into psqlscan.l
and let lex do it's job.

Since the result of a \gset is undefined if the query
fails it makes me nervous that psql would
continue running after \gset failure in a
non-interactive environment. Perhaps \gset/psql
should distinguish between interactive and
non-interactive environments in the same way
shell does? Do you have any use-cases where it
makes sense to continue after error in a
non-interactive environment?

As long as I'm talking crazy talk, why not
abandon psql as a shell language and instead make a
pl/pgsql interpreter with readlne() in front
of it? Solve all these language-related
issues by using an actual programming language. :-)

I hope at least some of the above is helpful
and I'm not just injecting noise into the system.

Regards,

Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-16 06:21:11
Message-ID: CAFj8pRDr9XHsy9cnnmipNwzjKYXqW6H3yteUM_v-YogA3TCMwQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2012/11/16 Karl O. Pinc <kop(at)meme(dot)com>:
> On 11/03/2012 01:45:36 PM, Pavel Stehule wrote:
>> Hello
>>
>> here is a updated patch
>
> This message does not appear to be threaded so I'm not
> sure I've read the whole back-history. Also, I don't
> really know what I'm doing. Never the less, I want
> to try to contribute to somebody else's patch so
> here's my comments. Make of them what you will.
>
> I know there's been criticism for touching too many
> different parts of the code, but writing your own
> mini-lexical analyzer does not make sense to me.
> There ought to be a clean way to move that into psqlscan.l
> and let lex do it's job.

it is about 20 rows only, so it is not critical and for me is not
important where parser is

>
> Since the result of a \gset is undefined if the query
> fails it makes me nervous that psql would
> continue running after \gset failure in a
> non-interactive environment. Perhaps \gset/psql
> should distinguish between interactive and
> non-interactive environments in the same way
> shell does? Do you have any use-cases where it
> makes sense to continue after error in a
> non-interactive environment?

No, I have not a use case for continuing after error - but any
continue after error is risk - so it is similar like any other code -
it is same risk as broken output for \g statement forwarded to file
and processed later.

It can be mentioned in documentation - so preferred usage of this
command is in stop error mode

>
> As long as I'm talking crazy talk, why not
> abandon psql as a shell language and instead make a
> pl/pgsql interpreter with readlne() in front
> of it? Solve all these language-related
> issues by using an actual programming language. :-)
>

I though about it more time, but I don't thinking so this has a sense.
Actually we cannot do perfect autocomplete for significantly simpler
SQL and there are lot of client side interprets - is not reason for
next one. I use psql together bash and it works well. But just very
simple task as storing some volatile data for repetitive usage is
relative laborious and it is a motivation for this patch. In psql I
can simply work with any fields of returned record - what is more
terrible work outside psql

Regards

Pavel Stehuke

> I hope at least some of the above is helpful
> and I'm not just injecting noise into the system.
>
> Regards,
>
> Karl <kop(at)meme(dot)com>
> Free Software: "You don't pay back, you pay forward."
> -- Robert A. Heinlein
>


From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-16 15:42:01
Message-ID: 1353080521.29131.0@mofo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi Pavel,

On 11/16/2012 12:21:11 AM, Pavel Stehule wrote:
> 2012/11/16 Karl O. Pinc <kop(at)meme(dot)com>:

> > As long as I'm talking crazy talk, why not
> > abandon psql as a shell language and instead make a
> > pl/pgsql interpreter with readlne() in front
> > of it? Solve all these language-related
> > issues by using an actual programming language. :-)

> I though about it more time, but I don't thinking so this has a
> sense.
> Actually we cannot do perfect autocomplete for significantly simpler
> SQL and there are lot of client side interprets - is not reason for
> next one. I use psql together bash and it works well. But just very
> simple task as storing some volatile data for repetitive usage is
> relative laborious and it is a motivation for this patch. In psql I
> can simply work with any fields of returned record - what is more
> terrible work outside psql

You might consider using "do".

http://www.postgresql.org/docs/9.1/static/sql-do.html

If you need to maintain a single connection you can do
some interesting things with socat to feed a running psql
in the background.

socat -u UNIX-RECV:/tmp/msock EXEC:psql &

Followed by lots of

echo bar | socat -u STDIN UNIX-SENDTO:/tmp/mysock

\o can be used to send output for pickup, although
you do need to fuss around with the asynchronous nature
of things to be sure you're waiting for output.
I used inotifywait for this. YMMV.

Regards,

Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-19 08:30:49
Message-ID: CAFj8pRAGY7L=bhUF7t38C4QppzcbFUdaMXdOU+xxv1OEz3oFAA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2012/11/16 Karl O. Pinc <kop(at)meme(dot)com>:
> Hi Pavel,
>
> On 11/16/2012 12:21:11 AM, Pavel Stehule wrote:
>> 2012/11/16 Karl O. Pinc <kop(at)meme(dot)com>:
>
>> > As long as I'm talking crazy talk, why not
>> > abandon psql as a shell language and instead make a
>> > pl/pgsql interpreter with readlne() in front
>> > of it? Solve all these language-related
>> > issues by using an actual programming language. :-)
>
>> I though about it more time, but I don't thinking so this has a
>> sense.
>> Actually we cannot do perfect autocomplete for significantly simpler
>> SQL and there are lot of client side interprets - is not reason for
>> next one. I use psql together bash and it works well. But just very
>> simple task as storing some volatile data for repetitive usage is
>> relative laborious and it is a motivation for this patch. In psql I
>> can simply work with any fields of returned record - what is more
>> terrible work outside psql
>
> You might consider using "do".

it is reason, why I don't thinking about plpgsql on client side. But I
don't understand how it is related to gset ?

I remember, there is one significant limit of DO statement - it cannot
return table - so it cannot substitute psql simple scripts. But I
don't would open this topic now - it is related to real stored
procedures implementation, and it is long time task. So gset allow
some simple tasks solve simply

Regards

Pavel Stehule

>
> http://www.postgresql.org/docs/9.1/static/sql-do.html
>
> If you need to maintain a single connection you can do
> some interesting things with socat to feed a running psql
> in the background.
>
> socat -u UNIX-RECV:/tmp/msock EXEC:psql &
>
> Followed by lots of
>
> echo bar | socat -u STDIN UNIX-SENDTO:/tmp/mysock
>
> \o can be used to send output for pickup, although
> you do need to fuss around with the asynchronous nature
> of things to be sure you're waiting for output.
> I used inotifywait for this. YMMV.
>
> Regards,
>
> Karl <kop(at)meme(dot)com>
> Free Software: "You don't pay back, you pay forward."
> -- Robert A. Heinlein
>


From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-19 15:17:19
Message-ID: 1353338239.9386.3@mofo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 11/19/2012 02:30:49 AM, Pavel Stehule wrote:
> Hello
>
> 2012/11/16 Karl O. Pinc <kop(at)meme(dot)com>:
> > Hi Pavel,
> >
> > On 11/16/2012 12:21:11 AM, Pavel Stehule wrote:
> >> 2012/11/16 Karl O. Pinc <kop(at)meme(dot)com>:
> >
> >> > As long as I'm talking crazy talk, why not
> >> > abandon psql as a shell language and instead make a
> >> > pl/pgsql interpreter with readlne() in front
> >> > of it? Solve all these language-related
> >> > issues by using an actual programming language. :-)
> >
> >> I though about it more time, but I don't thinking so this has a
> >> sense.

> > You might consider using "do".
>
> it is reason, why I don't thinking about plpgsql on client side. But
> I
> don't understand how it is related to gset ?

Because the plpgsql SELECT INTO sets variables from query results,
exactly what \gset does. You have to use EXECUTE
in plpgsql to do the substitution into statements, but that's
syntax.

>
> I remember, there is one significant limit of DO statement - it
> cannot
> return table - so it cannot substitute psql simple scripts.

Yes. I'm wrong. For some reason I thought you could use DO to make
an anonymous code block that would act as a SETOF function,
allowing RETURN NEXT expr (et-al) to be used in the
plpgsql code, allowing DO to return table results.
(Or, perhaps, instead, be used in place of a table in a SELECT
statement.) Oh well.

Regards,

Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-19 15:25:43
Message-ID: CAFj8pRDQqo-7+TY09=xU-Jt3M15-0v-DntK293cQ+w8kg6VbzQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2012/11/19 Karl O. Pinc <kop(at)meme(dot)com>:
> On 11/19/2012 02:30:49 AM, Pavel Stehule wrote:
>> Hello
>>
>> 2012/11/16 Karl O. Pinc <kop(at)meme(dot)com>:
>> > Hi Pavel,
>> >
>> > On 11/16/2012 12:21:11 AM, Pavel Stehule wrote:
>> >> 2012/11/16 Karl O. Pinc <kop(at)meme(dot)com>:
>> >
>> >> > As long as I'm talking crazy talk, why not
>> >> > abandon psql as a shell language and instead make a
>> >> > pl/pgsql interpreter with readlne() in front
>> >> > of it? Solve all these language-related
>> >> > issues by using an actual programming language. :-)
>> >
>> >> I though about it more time, but I don't thinking so this has a
>> >> sense.
>
>
>> > You might consider using "do".
>>
>> it is reason, why I don't thinking about plpgsql on client side. But
>> I
>> don't understand how it is related to gset ?
>
> Because the plpgsql SELECT INTO sets variables from query results,
> exactly what \gset does. You have to use EXECUTE
> in plpgsql to do the substitution into statements, but that's
> syntax.

yes, but I cannot set a psql variable

but a original proposal for gset was \exec .... into var :)

although \gset is more simply and there are no problem with multiline queries

>
>>
>> I remember, there is one significant limit of DO statement - it
>> cannot
>> return table - so it cannot substitute psql simple scripts.
>
> Yes. I'm wrong. For some reason I thought you could use DO to make
> an anonymous code block that would act as a SETOF function,
> allowing RETURN NEXT expr (et-al) to be used in the
> plpgsql code, allowing DO to return table results.
> (Or, perhaps, instead, be used in place of a table in a SELECT
> statement.) Oh well.

yes, I understand - "batch" model for DO is more natural, than
function - but it is not true :(.

I hope, so one time we will have a real stored procedures with unbound
queries. Then we can redefine DO behave, because it doesn't break
compatibility. But it is long way - maybe 9.5

Regards

Pavel

>
> Regards,
>
> Karl <kop(at)meme(dot)com>
> Free Software: "You don't pay back, you pay forward."
> -- Robert A. Heinlein
>


From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-19 16:12:57
Message-ID: m2fw45sh9y.fsf@2ndQuadrant.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Karl O. Pinc" <kop(at)meme(dot)com> writes:
> Yes. I'm wrong. For some reason I thought you could use DO to make
> an anonymous code block that would act as a SETOF function,
> allowing RETURN NEXT expr (et-al) to be used in the
> plpgsql code, allowing DO to return table results.
> (Or, perhaps, instead, be used in place of a table in a SELECT
> statement.) Oh well.

My key for remembering about that point is that DO is a utility command,
not a query. Now, the proposal I pushed last time we opened that very
can of worms was to have inline functions rather than anonymous code
blocks:

WITH FUNCTION foo(integer) returns bigint language SQL AS $$
SELECT $1 + 1;
$$,

Not sure how much that relates to $topic, but still something that
raises in my mind with enough presence that I need to write about it so
that it stops calling for attention :)

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support


From: Piyush Newe <piyush(dot)newe(at)enterprisedb(dot)com>
To: Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>
Cc: "Karl O(dot) Pinc" <kop(at)meme(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-27 09:49:23
Message-ID: CAML=0Spu4ZdYgZmADQgtA671jza746M-OOpEN9RT6-yTKe-UMw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Just another thought !

When we are setting up the variable using \gset, I feel their should be a
provision
to drop a particular variable.

Internally, all the variables are set into "VariableSpace" linked-list. We
should provide
a command to Drop a particular variable, because in some cases unnecessary
the
variable count is increasing & consuming a VariableSpace.

We might use two different variables for two different queries, but if we
are not going
to use the first variable in further execution, then unnecessary we are
consuming a
space for 1st variable in the "VariableSpace". In such cases, user will
drop the 1st
variable.

This particular feature/mechanism is useful for a queries which returns a
single row.
So user will be using such technique for multiple queries. In such cases,
user might
need to create multiple variables. Hence I thoughts so.

Let me know if such mechanism is already exists & I am missing the same.

On Mon, Nov 19, 2012 at 9:42 PM, Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>wrote:

> "Karl O. Pinc" <kop(at)meme(dot)com> writes:
> > Yes. I'm wrong. For some reason I thought you could use DO to make
> > an anonymous code block that would act as a SETOF function,
> > allowing RETURN NEXT expr (et-al) to be used in the
> > plpgsql code, allowing DO to return table results.
> > (Or, perhaps, instead, be used in place of a table in a SELECT
> > statement.) Oh well.
>
> My key for remembering about that point is that DO is a utility command,
> not a query. Now, the proposal I pushed last time we opened that very
> can of worms was to have inline functions rather than anonymous code
> blocks:
>
> WITH FUNCTION foo(integer) returns bigint language SQL AS $$
> SELECT $1 + 1;
> $$,
>
> Not sure how much that relates to $topic, but still something that
> raises in my mind with enough presence that I need to write about it so
> that it stops calling for attention :)
>
> Regards,
> --
> Dimitri Fontaine
> http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>

--
--
Piyush S Newe
Principal Engineer
EnterpriseDB
office: +91 20 3058 9500
www.enterprisedb.com

Website: www.enterprisedb.com
EnterpriseDB Blog: http://blogs.enterprisedb.com/
Follow us on Twitter: http://www.twitter.com/enterprisedb

This e-mail message (and any attachment) is intended for the use of the
individual or entity to whom it is addressed. This message contains
information from EnterpriseDB Corporation that may be privileged,
confidential, or exempt from disclosure under applicable law. If you are
not the intended recipient or authorized to receive this for the intended
recipient, any use, dissemination, distribution, retention, archiving, or
copying of this communication is strictly prohibited. If you have received
this e-mail in error, please notify the sender immediately by reply e-mail
and delete this message.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Piyush Newe <piyush(dot)newe(at)enterprisedb(dot)com>
Cc: Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>, "Karl O(dot) Pinc" <kop(at)meme(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gset updated patch
Date: 2012-11-27 09:59:07
Message-ID: CAFj8pRC7YE+Za3qsc3BsWjTzkV3VLSsHtAY0Zw9mNHKV5jPvrA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2012/11/27 Piyush Newe <piyush(dot)newe(at)enterprisedb(dot)com>:
>
> Just another thought !
>
> When we are setting up the variable using \gset, I feel their should be a
> provision
> to drop a particular variable.
>
> Internally, all the variables are set into "VariableSpace" linked-list. We
> should provide
> a command to Drop a particular variable, because in some cases unnecessary
> the
> variable count is increasing & consuming a VariableSpace.
>
> We might use two different variables for two different queries, but if we
> are not going
> to use the first variable in further execution, then unnecessary we are
> consuming a
> space for 1st variable in the "VariableSpace". In such cases, user will drop
> the 1st
> variable.
>
> This particular feature/mechanism is useful for a queries which returns a
> single row.
> So user will be using such technique for multiple queries. In such cases,
> user might
> need to create multiple variables. Hence I thoughts so.
>

sorry, I don't understand

now, when we set variable by empty value, then we remove variable

???

regards

Pavel

> Let me know if such mechanism is already exists & I am missing the same.
>
>
> On Mon, Nov 19, 2012 at 9:42 PM, Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>
> wrote:
>>
>> "Karl O. Pinc" <kop(at)meme(dot)com> writes:
>> > Yes. I'm wrong. For some reason I thought you could use DO to make
>> > an anonymous code block that would act as a SETOF function,
>> > allowing RETURN NEXT expr (et-al) to be used in the
>> > plpgsql code, allowing DO to return table results.
>> > (Or, perhaps, instead, be used in place of a table in a SELECT
>> > statement.) Oh well.
>>
>> My key for remembering about that point is that DO is a utility command,
>> not a query. Now, the proposal I pushed last time we opened that very
>> can of worms was to have inline functions rather than anonymous code
>> blocks:
>>
>> WITH FUNCTION foo(integer) returns bigint language SQL AS $$
>> SELECT $1 + 1;
>> $$,
>>
>> Not sure how much that relates to $topic, but still something that
>> raises in my mind with enough presence that I need to write about it so
>> that it stops calling for attention :)
>>
>> Regards,
>> --
>> Dimitri Fontaine
>> http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support
>>
>>
>> --
>> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-hackers
>
>
>
>
> --
> --
> Piyush S Newe
> Principal Engineer
> EnterpriseDB
> office: +91 20 3058 9500
> www.enterprisedb.com
>
> Website: www.enterprisedb.com
> EnterpriseDB Blog: http://blogs.enterprisedb.com/
> Follow us on Twitter: http://www.twitter.com/enterprisedb
>
> This e-mail message (and any attachment) is intended for the use of the
> individual or entity to whom it is addressed. This message contains
> information from EnterpriseDB Corporation that may be privileged,
> confidential, or exempt from disclosure under applicable law. If you are not
> the intended recipient or authorized to receive this for the intended
> recipient, any use, dissemination, distribution, retention, archiving, or
> copying of this communication is strictly prohibited. If you have received
> this e-mail in error, please notify the sender immediately by reply e-mail
> and delete this message.
>