pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedcan I do this.
7+ messages / 6 participants
[nested] [flat]
* can I do this.
@ 1999-11-25 09:22 Jason C. Leach <jcl@mail.ocis.net>
0 siblings, 1 reply; 7+ messages in thread
From: Jason C. Leach @ 1999-11-25 09:22 UTC (permalink / raw)
To: pgsql-list <pgsql-general@hub.org>
hi,
I'm wondering if I can set a trigger or stored procedure that will run a
perl script?
Thanks,
Jason.
--
.............
......... Jason C. Leach
...... University College of the Cariboo
... jcl@mail.ocis.net.
.. http://www.ocis.net/~jcl
.
The Search for Extraterrestrial Intelligence from Home:
http://setiathome.ssl.berkeley.edu
LINUX!
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [GENERAL] can I do this.
@ 1999-11-27 01:06 Peter Eisentraut <peter_e@gmx.net>
parent: Jason C. Leach <jcl@mail.ocis.net>
0 siblings, 1 reply; 7+ messages in thread
From: Peter Eisentraut @ 1999-11-27 01:06 UTC (permalink / raw)
To: Jason C. Leach <jcl@mail.ocis.net>; +Cc: pgsql-list <pgsql-general@hub.org>
On 1999-11-25, Jason C. Leach mentioned:
> I'm wondering if I can set a trigger or stored procedure that will run a
> perl script?
Your best bet will probably be a wrapper function in C that will call the
Perl program via system(), for example.
--
Peter Eisentraut Sernanders väg 10:115
peter_e@gmx.net 75262 Uppsala
http://yi.org/peter-e/ Sweden
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: [GENERAL] can I do this.
@ 1999-11-27 17:40 Stuart Rison <rison@biochemistry.ucl.ac.uk>
parent: Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 7+ messages in thread
From: Stuart Rison @ 1999-11-27 17:40 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: Jason C. Leach <jcl@mail.ocis.net>; pgsql-list <pgsql-general@hub.org>
Yes, but wasn't there talk -a little while back- of actually implementing
Perl functions directly (i.e. not via a C wrapper).
I remember there was a fair bit of support for doing so but I haven't
heard any more!
Anybody out there doing it? I'd really love it! I'd help but I only
"program" Perl... hence the request ;)
Cheers,
S.
On Sat, 27 Nov 1999, Peter Eisentraut wrote:
> On 1999-11-25, Jason C. Leach mentioned:
>
> > I'm wondering if I can set a trigger or stored procedure that will run a
> > perl script?
>
> Your best bet will probably be a wrapper function in C that will call the
> Perl program via system(), for example.
>
> --
> Peter Eisentraut Sernanders väg 10:115
> peter_e@gmx.net 75262 Uppsala
> http://yi.org/peter-e/ Sweden
>
>
>
> ************
>
Stuart C. G. Rison
Department of Biochemistry and Molecular Biology
6th floor, Darwin Building, University College London (UCL)
Gower Street, London, WC1E 6BT, United Kingdom
Tel. 0207 504 2303, Fax. 0207 380 7193
e-mail: rison@biochem.ucl.ac.uk
^ permalink raw reply [nested|flat] 7+ messages in thread
* Can I do this?
@ 2020-01-16 12:28 stan <stanb@panix.com>
0 siblings, 2 replies; 7+ messages in thread
From: stan @ 2020-01-16 12:28 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
I am trying to create a function to automatically create a reference value
when a record is inserted into a table. I want the reference value to
consist of the user that is doing the insert, plus a couple of dates, plus
a sequence number, where the sequence number will increment every time a
given user inserts a record. because this sequence number is user specific,
my first thought is not to use a set of sequences for it, but to do this by
selecting the maximum sequence number that user has entered in the past.
So, I have a function that gets all the data, and concatenates it into a
string with the exception of the sequence. For that component, I have the
following test select that works.
SELECT NULLIF(regexp_replace(report_no, '\D','','g'), '')::numeric AS result
FROM
expense_report_instance
WHERE
/* NEW.project_key */ 123 = project_key;
But, when I add the requisite MAX clause, I get a syntax error.
SELECT MAX(NULLIF(regexp_replace(report_no, '\D','','g'), '')::numeric
FROM
expense_report_instance
WHERE
/* NEW.project_key */ 123 = project_key);
Is there a way I can make this work?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Can I do this?
@ 2020-01-16 14:45 Justin <zzzzz.graf@gmail.com>
parent: stan <stanb@panix.com>
1 sibling, 0 replies; 7+ messages in thread
From: Justin @ 2020-01-16 14:45 UTC (permalink / raw)
To: stan <stanb@panix.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Hi Stan
in you code sample there are "(" mis-matched, "MAX(" matches to "=
project_key)";
it should be
MAX(NULLIF(regexp_replace(report_no, '\D','','g'), '')::numeric)
I do exactly what you do, and you are correct sequences are not a good fit
I typically do something like this for
select 'username' || 'more text' || Max(count)+1::text from
myreport_counter_table group by userName, report_id where userName = 'the
user ' and report_id = 12
On Thu, Jan 16, 2020 at 7:28 AM stan <stanb@panix.com> wrote:
> I am trying to create a function to automatically create a reference value
> when a record is inserted into a table. I want the reference value to
> consist of the user that is doing the insert, plus a couple of dates, plus
> a sequence number, where the sequence number will increment every time a
> given user inserts a record. because this sequence number is user specific,
> my first thought is not to use a set of sequences for it, but to do this
> by
> selecting the maximum sequence number that user has entered in the past.
>
> So, I have a function that gets all the data, and concatenates it into a
> string with the exception of the sequence. For that component, I have the
> following test select that works.
>
>
> SELECT NULLIF(regexp_replace(report_no, '\D','','g'), '')::numeric AS
> result
> FROM
> expense_report_instance
> WHERE
> /* NEW.project_key */ 123 = project_key;
>
> But, when I add the requisite MAX clause, I get a syntax error.
>
> SELECT MAX(NULLIF(regexp_replace(report_no, '\D','','g'), '')::numeric
> FROM
> expense_report_instance
> WHERE
> /* NEW.project_key */ 123 = project_key);
>
> Is there a way I can make this work?
>
>
> --
> "They that would give up essential liberty for temporary safety deserve
> neither liberty nor safety."
> -- Benjamin Franklin
>
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Can I do this?
@ 2020-01-16 15:39 Michael Nolan <htfoot@gmail.com>
parent: stan <stanb@panix.com>
1 sibling, 1 reply; 7+ messages in thread
From: Michael Nolan @ 2020-01-16 15:39 UTC (permalink / raw)
To: stan <stanb@panix.com>; +Cc: pgsql-general@lists.postgresql.org
On Thu, Jan 16, 2020 at 6:28 AM stan <stanb@panix.com> wrote:
> I am trying to create a function to automatically create a reference value
> when a record is inserted into a table. I want the reference value to
> consist of the user that is doing the insert, plus a couple of dates, plus
> a sequence number, where the sequence number will increment every time a
> given user inserts a record. because this sequence number is user specific,
> my first thought is not to use a set of sequences for it, but to do this
> by
> selecting the maximum sequence number that user has entered in the past.
>
> What happens if two transactions by/for the same user are committed at
around the same point in time? The advantage of sequences is they're
guaranteed to be unique, I'm not sure counting the number of previous
records and adding one will always assure that.
--
Mike Nolan
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Can I do this?
@ 2020-01-16 16:38 Justin <zzzzz.graf@gmail.com>
parent: Michael Nolan <htfoot@gmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: Justin @ 2020-01-16 16:38 UTC (permalink / raw)
To: Michael Nolan <htfoot@gmail.com>; +Cc: stan <stanb@panix.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
it does not, but the odds the same user will run this command by this id
in two different sessions at the same time are very low.
this type of code exist for PO,SO, Invoices, to assign the next line item
# in many apps.
On Thu, Jan 16, 2020 at 10:40 AM Michael Nolan <htfoot@gmail.com> wrote:
>
>
> On Thu, Jan 16, 2020 at 6:28 AM stan <stanb@panix.com> wrote:
>
>> I am trying to create a function to automatically create a reference value
>> when a record is inserted into a table. I want the reference value to
>> consist of the user that is doing the insert, plus a couple of dates, plus
>> a sequence number, where the sequence number will increment every time a
>> given user inserts a record. because this sequence number is user
>> specific,
>> my first thought is not to use a set of sequences for it, but to do this
>> by
>> selecting the maximum sequence number that user has entered in the past.
>>
>> What happens if two transactions by/for the same user are committed at
> around the same point in time? The advantage of sequences is they're
> guaranteed to be unique, I'm not sure counting the number of previous
> records and adding one will always assure that.
> --
> Mike Nolan
>
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2020-01-16 16:38 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-11-25 09:22 can I do this. Jason C. Leach <jcl@mail.ocis.net>
1999-11-27 01:06 ` Peter Eisentraut <peter_e@gmx.net>
1999-11-27 17:40 ` Stuart Rison <rison@biochemistry.ucl.ac.uk>
2020-01-16 12:28 Can I do this? stan <stanb@panix.com>
2020-01-16 14:45 ` Re: Can I do this? Justin <zzzzz.graf@gmail.com>
2020-01-16 15:39 ` Re: Can I do this? Michael Nolan <htfoot@gmail.com>
2020-01-16 16:38 ` Re: Can I do this? Justin <zzzzz.graf@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox