473,385 Members | 1,359 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,385 software developers and data experts.

plpgsql extract epoch problem

Hey all

I am trying to extract the epoch from a timestamp variable in plpgsql.
The function is as follows:

create or replace function test() returns integer as '
declare
_test timestamp with time zone;
_f integer;
begin
_test := current_timestamp;
_f := extract(epoch from timestamp _test);
return _f;
end;' language 'plpgsql';

Any ideas why this will not work????

The error is as follows:
pts=> select test();
WARNING: Error occurred while executing PL/pgSQL function test
WARNING: line 6 at assignment
ERROR: parser: parse error at or near "$1" at character 40

And that is the _test variable

Any help greatly apprechiated
Darren
---------------------------(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
2 3007
Sorry found the answer
I was taking the docs to literal

It should be extract(epoch from _test)

Sorry for the email
Darren

Darren Ferguson wrote:
Hey all

I am trying to extract the epoch from a timestamp variable in plpgsql.
The function is as follows:

create or replace function test() returns integer as '
declare
_test timestamp with time zone;
_f integer;
begin
_test := current_timestamp;
_f := extract(epoch from timestamp _test);
return _f;
end;' language 'plpgsql';

Any ideas why this will not work????

The error is as follows:
pts=> select test();
WARNING: Error occurred while executing PL/pgSQL function test
WARNING: line 6 at assignment
ERROR: parser: parse error at or near "$1" at character 40

And that is the _test variable

Any help greatly apprechiated
Darren
---------------------------(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 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 #2
On Wed, Oct 22, 2003 at 12:50:22PM -0400, Darren Ferguson wrote:
create or replace function test() returns integer as '
declare
_test timestamp with time zone;
_f integer;
begin
_test := current_timestamp;
_f := extract(epoch from timestamp _test);
Why not simply
_f := extract(epoch from _test);
?
return _f;
end;' language 'plpgsql';


--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Hay que recordar que la existencia en el cosmos, y particularmente la
elaboración de civilizaciones dentre de él no son, por desgracia,
nada idílicas" (Ijon Tichy)

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

Nov 12 '05 #3

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

Similar topics

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...
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...
1
by: Randall Skelton | last post by:
Can someone explain why the latter query uses an index scan while the former uses a sequence scan? I have tried all sorts of casting in the first case but I cannot get the index scan. Cheers,...
5
by: Thomas Chille | last post by:
Hi, i am playing around with PLpgSQL and can not solve one problem: I am fetching some rows of a special rowtype and wanna give this rows step by step to a function with this rowtype as...
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...
1
by: Karl O. Pinc | last post by:
FYI, mostly. But I do have questions as to how to write code that will continue to work in subsequent postgresql versions. See code below. begintest() uses EXIT to exit a BEGIN block from...
0
by: Stefano Bonnin | last post by:
Hi, I have a problem with plpgsql and postgres8.0.0beta2 When I execute an insert on "mytable" the psql client returns me the following: **** server closed the connection unexpectedly This...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.