pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: stan <stanb@panix.com>
To: pgsql-general@lists.postgresql.org
Subject: Can I do this?
Date: Thu, 16 Jan 2020 07:28:41 -0500
Message-ID: <20200116122841.GA25728@panix.com> (raw)

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





view thread (7+ messages)  latest in thread

Message-ID: <20200116122841.GA25728@panix.com>
Permalink:  ../20200116122841.GA25728@panix.com/
Also on:    postgresql.org/message-id/20200116122841.GA25728@panix.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: stanb@panix.com
  Subject: Re: Can I do this?
  In-Reply-To: <20200116122841.GA25728@panix.com>
  References: <20200116122841.GA25728@panix.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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