473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Problems with PLPGSQL

Hi,
I have a problem with quoting in one of my functions:

now TIMESTAMP := ''now'';
FOR myRec IN SELECT * FROM myTable WHERE job_end + ''360 Min'' > now LOOP

I want to replace the 360 with the contents of a passed value

but for some reason I can't quote it. ... job_end + ''$1 Min'' does not
work.

Could anyone help me out here ?
On the subject:
The whole quoting in PLPGSQL seems to create many people a headache...
is there any plan to make it a bit more user friendly?

Thanks
Alx


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
10 1518
Hi Alex,

If you want to achieve say '360 min' as the string you will have use
concatenation:

FOR myRec IN SELECT * FROM myTable WHERE job_end + ($1::text || '' Min'') >
now LOOP

The syntax is SQL rather than PHP-like.

Rgds,

Jason

On Thu, 6 Nov 2003 03:13 pm, Alex wrote:
Hi,
I have a problem with quoting in one of my functions:

now TIMESTAMP := ''now'';
FOR myRec IN SELECT * FROM myTable WHERE job_end + ''360 Min'' > now LOOP

I want to replace the 360 with the contents of a passed value

but for some reason I can't quote it. ... job_end + ''$1 Min'' does not
work.

Could anyone help me out here ?
On the subject:
The whole quoting in PLPGSQL seems to create many people a headache...
is there any plan to make it a bit more user friendly?

Thanks
Alx


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #2
On Thursday 06 November 2003 04:13, Alex wrote:
Hi,
I have a problem with quoting in one of my functions:

now TIMESTAMP := ''now'';


Your main question has been answered, but you might want now() rather than
''now''. Off the top of my head, I think the ''now'' might get compiled as a
value on the first run and stay at that value.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #3
Hi Jason,
thanks, for the reply. Tried that one but still getting an error

Unable to identify an operator + for types timestamp without time zone
and text ....

Alex

Jason Godden wrote:
Hi Alex,

If you want to achieve say '360 min' as the string you will have use
concatenation:

FOR myRec IN SELECT * FROM myTable WHERE job_end + ($1::text || '' Min'') >
now LOOP

The syntax is SQL rather than PHP-like.

Rgds,

Jason

On Thu, 6 Nov 2003 03:13 pm, Alex wrote:

Hi,
I have a problem with quoting in one of my functions:

now TIMESTAMP := ''now'';
FOR myRec IN SELECT * FROM myTable WHERE job_end + ''360 Min'' > now LOOP

I want to replace the 360 with the contents of a passed value

but for some reason I can't quote it. ... job_end + ''$1 Min'' does not
work.

Could anyone help me out here ?
On the subject:
The whole quoting in PLPGSQL seems to create many people a headache...
is there any plan to make it a bit more user friendly?

Thanks
Alx


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #4
Hi Richard,
as for the timestamp, both ways work fine, but the other problem still
exists. using a
''60 Min'' works just fine, but WHERE job_end + ($1::text || '' Min'' )
now does not. job_end is timestamp without tz

Alex

Richard Huxton wrote:
On Thursday 06 November 2003 04:13, Alex wrote:

Hi,
I have a problem with quoting in one of my functions:

now TIMESTAMP := ''now'';


Your main question has been answered, but you might want now() rather than
''now''. Off the top of my head, I think the ''now'' might get compiled as a
value on the first run and stay at that value.


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #5
Hello

Don't use now or current_time, use
LOCALTIMESTAMP

CURRENT_TIME and CURRENT_TIMESTAMP deliver values with time zone;
LOCALTIME and LOCALTIMESTAMP deliver values without time zone.

Pavel

On Thu, 6 Nov 2003, Alex wrote:
Hi Richard,
as for the timestamp, both ways work fine, but the other problem still
exists. using a
''60 Min'' works just fine, but WHERE job_end + ($1::text || '' Min'' )
> now

does not. job_end is timestamp without tz

Alex

Richard Huxton wrote:
On Thursday 06 November 2003 04:13, Alex wrote:

Hi,
I have a problem with quoting in one of my functions:

now TIMESTAMP := ''now'';


Your main question has been answered, but you might want now() rather than
''now''. Off the top of my head, I think the ''now'' might get compiled as a
value on the first run and stay at that value.


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #6
On Thursday 06 November 2003 10:00, Alex wrote:
Hi Richard,
as for the timestamp, both ways work fine, but the other problem still
exists. using a
''60 Min'' works just fine, but WHERE job_end + ($1::text || '' Min'' )


You probably want a cast:
+ ($1::text || '' min'')::interval

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #7
That works.
Thanks a lot.
Alex

Richard Huxton wrote:
On Thursday 06 November 2003 10:00, Alex wrote:

Hi Richard,
as for the timestamp, both ways work fine, but the other problem still
exists. using a
''60 Min'' works just fine, but WHERE job_end + ($1::text || '' Min'' )


You probably want a cast:
+ ($1::text || '' min'')::interval


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #8
On Thu, Nov 06, 2003 at 01:13:00PM +0900, Alex wrote:
On the subject:
The whole quoting in PLPGSQL seems to create many people a headache...
is there any plan to make it a bit more user friendly?


Yes, there's a new cool quoting method that will make it much headache
unfriendly. It will probably be there in 7.5 (not 7.4, sorry).

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Uno combate cuando es necesario... ˇno cuando está de humor!
El humor es para el ganado, o para hacer el amor, o para tocar el
baliset. No para combatir." (Gurney Halleck)

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #9
On Thu, Nov 06, 2003 at 18:17:52 +0900,
Alex <al**@meerkatsoft.com> wrote:
Hi Jason,
thanks, for the reply. Tried that one but still getting an error

Unable to identify an operator + for types timestamp without time zone
and text ....


You probably need an explicit cast from text to interval. An untyped
(unknown) string gets handled differently than one of type text.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #10
Richard Huxton <de*@archonet.com> writes:
On Thursday 06 November 2003 10:00, Alex wrote:
as for the timestamp, both ways work fine, but the other problem still
exists. using a
''60 Min'' works just fine, but WHERE job_end + ($1::text || '' Min'' )
You probably want a cast:
+ ($1::text || '' min'')::interval


This is pretty much the hard way, though. A better idea is to use the
number-times-interval operator:

timestampvalue + $1 * '1 min'::interval;

Easier to write and faster.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Flash | last post by:
I have been playing with postgresql at home. This is on a fedora core 2 linux box. Here are the packages yum installed: $ rpm -qa | grep postgres postgresql-libs-7.4.2-1...
0
by: andy morrow | last post by:
hi, fairly new to postgres admin stuff...... i have a production machine that is running postgresql 7.1.3 also, there's a test machine which already had 7.0.3, and which i newly installed...
6
by: Martin Marques | last post by:
We are trying to make some things work with plpgsql. The problem is that I built several functions that call one another, and I thought that the way of calling it was just making the assign: ...
1
by: Rajesh Kumar Mallah | last post by:
Hi, profile_row profile_master%ROWTYPE; in a plpgsql function gives the error below tradein_clients=# SELECT general.create_accounts(); WARNING: plpgsql: ERROR during compile of...
0
by: Steve Wampler | last post by:
Hmmm, I've always used plpgsql.so (also formerly known as libplpgsql.so, I think...) as in: CREATE FUNCTION plpgsql_call_handler () RETURNS language_handler AS '/usr/lib/plpgsql.so',...
10
by: lnd | last post by:
After copied pg database from one PC to another -I could not find plpgsql function(s) in the copied database. -had to instal plpgsql language handler again -whilst tables and data moved...
4
by: Bill Moran | last post by:
I've got a bit of a strange problem that's causing me some MAJOR headaches. I'm developing the server-side of a large database application in PostgreSQL. This consists of a C daemon, and a LOT...
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
0
by: sripathy sena | last post by:
Hi, I am trying to install OPenacs with postgres 7.4.3 as the database. The openacs requires plpgsql to be installed. When I try to do this by running "CREATELANG plpgsql template1". I get a...
9
by: Karl O. Pinc | last post by:
I want to return multiple values, but not a set, only a single row, from a plpgsql function and I can't seem to get it to work. (I suppose I'd be happy to return a set, but I can't seem to make...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.