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

composite type and assignment in plpgsql

what's wrong with this?

create type tSession
as ( ty_found boolean, ty_Session char(32) );

create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
--HERE!!!
thisSession := ( ''t'', md5( now( ) || rand( ) ) );
return thisSession;
end;
' language plpgsql;
thx
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #1
8 2247
Ivan Sergio Borgonovo wrote:
what's wrong with this?

create type tSession
as ( ty_found boolean, ty_Session char(32) );

create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
--HERE!!!
thisSession := ( ''t'', md5( now( ) || rand( ) ) );
- md5 takes TEXT as an argument, not a numeric type
- assign each variable of type tSession to its corresponding value:
thisSession.ty_found := ''t'';
thisSession.ty_session := md5(CAST((now( )) AS TEXT));
I haven't looked up the rand() function, but you can see from this how
you would cast it and now() to text.
return thisSession;
end;
' language plpgsql;
thx
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

And then you can get the results:
select * from getsessionid(1);
imperial=# select * from getsessionid(1);
ty_found | ty_session
----------+----------------------------------
t | cf76cca2b562a0ead48d3eb3810f51cc
(1 row)
hth

Ron

---------------------------(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 23 '05 #2
Ivan Sergio Borgonovo wrote:
what's wrong with this?

create type tSession
as ( ty_found boolean, ty_Session char(32) );

create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
--HERE!!!
thisSession := ( ''t'', md5( now( ) || rand( ) ) );
- md5 takes TEXT as an argument, not a numeric type
- assign each variable of type tSession to its corresponding value:
thisSession.ty_found := ''t'';
thisSession.ty_session := md5(CAST((now( )) AS TEXT));
I haven't looked up the rand() function, but you can see from this how
you would cast it and now() to text.
return thisSession;
end;
' language plpgsql;
thx
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

And then you can get the results:
select * from getsessionid(1);
imperial=# select * from getsessionid(1);
ty_found | ty_session
----------+----------------------------------
t | cf76cca2b562a0ead48d3eb3810f51cc
(1 row)
hth

Ron

---------------------------(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 23 '05 #3
Ron St-Pierre wrote:
Ivan Sergio Borgonovo wrote:
what's wrong with this?

create type tSession
as ( ty_found boolean, ty_Session char(32) );

create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
--HERE!!!
thisSession := ( ''t'', md5( now( ) || rand( ) ) );

- md5 takes TEXT as an argument, not a numeric type
- assign each variable of type tSession to its corresponding value:
thisSession.ty_found := ''t'';
thisSession.ty_session := md5(CAST((now( )) AS TEXT));
I haven't looked up the rand() function, but you can see from this how
you would cast it and now() to text.
return thisSession;
end;
' language plpgsql;
thx
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

And then you can get the results:
select * from getsessionid(1);
imperial=# select * from getsessionid(1);
ty_found | ty_session
----------+----------------------------------
t | cf76cca2b562a0ead48d3eb3810f51cc
(1 row)
hth

Ron

In the above reply, I forgot to mention that you are not using the
integer you are passing in as an argument. If you need it (rand()?)
you'll have to declare it:
myInt ALIAS FOR $1;
or use it explicitly with just the name: $1

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

Nov 23 '05 #4
Ron St-Pierre wrote:
Ivan Sergio Borgonovo wrote:
what's wrong with this?

create type tSession
as ( ty_found boolean, ty_Session char(32) );

create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
--HERE!!!
thisSession := ( ''t'', md5( now( ) || rand( ) ) );

- md5 takes TEXT as an argument, not a numeric type
- assign each variable of type tSession to its corresponding value:
thisSession.ty_found := ''t'';
thisSession.ty_session := md5(CAST((now( )) AS TEXT));
I haven't looked up the rand() function, but you can see from this how
you would cast it and now() to text.
return thisSession;
end;
' language plpgsql;
thx
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

And then you can get the results:
select * from getsessionid(1);
imperial=# select * from getsessionid(1);
ty_found | ty_session
----------+----------------------------------
t | cf76cca2b562a0ead48d3eb3810f51cc
(1 row)
hth

Ron

In the above reply, I forgot to mention that you are not using the
integer you are passing in as an argument. If you need it (rand()?)
you'll have to declare it:
myInt ALIAS FOR $1;
or use it explicitly with just the name: $1

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

Nov 23 '05 #5
On Tue, 27 Apr 2004 10:12:13 -0700
Ron St-Pierre <rs*******@syscor.com> wrote:
Ivan Sergio Borgonovo wrote:

--HERE!!!
thisSession := ( ''t'', md5( now( ) || rand( ) ) );

- md5 takes TEXT as an argument, not a numeric type


Since it works you surely fixed my code but this should't be an issue
since I tried

test1=# select md5( now( ) || random( ) );
md5
----------------------------------
154e804967451148bba5f28e044be828
(1 row)

and

test1=# select md5( random( ) );
md5
----------------------------------
31313f537b69d5ffe61be024a40b807e
(1 row)

and they worked.

and yeah I messed up remembering mySQL code and wrote rand( ) inspite
of random( )

Can't user composite type be initialized in a shortest way?
eg. ( ( ), ( ), , ( ), , , ( ), ...)
I thought they could. I saw a similar syntax somewhere in the docs. Am
I daydreaming?

One more thing about the first example presented in this page:
http://www.postgresql.org/docs/7.4/s...pressions.html

I just tried
create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
thisSession.ty_Found := ''t'';
thisSession.ty_Session := now( );
return thisSession;
end;
' language plpgsql;

and it returns execution time not "plan" time. Does "plan" time is
strictly referred to SQL statements?
thanks for your help
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #6
On Tue, 27 Apr 2004 10:12:13 -0700
Ron St-Pierre <rs*******@syscor.com> wrote:
Ivan Sergio Borgonovo wrote:

--HERE!!!
thisSession := ( ''t'', md5( now( ) || rand( ) ) );

- md5 takes TEXT as an argument, not a numeric type


Since it works you surely fixed my code but this should't be an issue
since I tried

test1=# select md5( now( ) || random( ) );
md5
----------------------------------
154e804967451148bba5f28e044be828
(1 row)

and

test1=# select md5( random( ) );
md5
----------------------------------
31313f537b69d5ffe61be024a40b807e
(1 row)

and they worked.

and yeah I messed up remembering mySQL code and wrote rand( ) inspite
of random( )

Can't user composite type be initialized in a shortest way?
eg. ( ( ), ( ), , ( ), , , ( ), ...)
I thought they could. I saw a similar syntax somewhere in the docs. Am
I daydreaming?

One more thing about the first example presented in this page:
http://www.postgresql.org/docs/7.4/s...pressions.html

I just tried
create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
thisSession.ty_Found := ''t'';
thisSession.ty_Session := now( );
return thisSession;
end;
' language plpgsql;

and it returns execution time not "plan" time. Does "plan" time is
strictly referred to SQL statements?
thanks for your help
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #7
Ivan Sergio Borgonovo wrote:
On Tue, 27 Apr 2004 10:12:13 -0700

thisSession := ( ''t'', md5( now( ) || rand( ) ) );

- md5 takes TEXT as an argument, not a numeric type


Since it works you surely fixed my code but this should't be an issue
since I tried

test1=# select md5( now( ) || random( ) );
md5
----------------------------------
154e804967451148bba5f28e044be828
(1 row)

and

test1=# select md5( random( ) );
md5
----------------------------------
31313f537b69d5ffe61be024a40b807e
(1 row)

and they worked.

Yeah, they worked for me too. I was just looking at the docs and saw the
TEXT argument.........

and yeah I messed up remembering mySQL code and wrote rand( ) inspite
of random( )

Can't user composite type be initialized in a shortest way?
eg. ( ( ), ( ), , ( ), , , ( ), ...)
I thought they could. I saw a similar syntax somewhere in the docs. Am
I daydreaming?
I don't know.....

One more thing about the first example presented in this page:
http://www.postgresql.org/docs/7.4/s...pressions.html

I just tried
create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
thisSession.ty_Found := ''t'';
thisSession.ty_Session := now( );
return thisSession;
end;
' language plpgsql;

and it returns execution time not "plan" time. Does "plan" time is
strictly referred to SQL statements?

I'm not sure I understand what you're asking here. CURRENT_TIMESTAMP and
now() return the start time of the current transaction, would that be
the "plan" time? The timeofday() function returns the "wall clock" time
and advances during transactions. I think that this would be the
"execution" time.

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

Nov 23 '05 #8
Ivan Sergio Borgonovo wrote:
On Tue, 27 Apr 2004 10:12:13 -0700

thisSession := ( ''t'', md5( now( ) || rand( ) ) );

- md5 takes TEXT as an argument, not a numeric type


Since it works you surely fixed my code but this should't be an issue
since I tried

test1=# select md5( now( ) || random( ) );
md5
----------------------------------
154e804967451148bba5f28e044be828
(1 row)

and

test1=# select md5( random( ) );
md5
----------------------------------
31313f537b69d5ffe61be024a40b807e
(1 row)

and they worked.

Yeah, they worked for me too. I was just looking at the docs and saw the
TEXT argument.........

and yeah I messed up remembering mySQL code and wrote rand( ) inspite
of random( )

Can't user composite type be initialized in a shortest way?
eg. ( ( ), ( ), , ( ), , , ( ), ...)
I thought they could. I saw a similar syntax somewhere in the docs. Am
I daydreaming?
I don't know.....

One more thing about the first example presented in this page:
http://www.postgresql.org/docs/7.4/s...pressions.html

I just tried
create or replace function GetSessionID( integer )
returns tSession as '
declare
thisSession tSession;
begin
thisSession.ty_Found := ''t'';
thisSession.ty_Session := now( );
return thisSession;
end;
' language plpgsql;

and it returns execution time not "plan" time. Does "plan" time is
strictly referred to SQL statements?

I'm not sure I understand what you're asking here. CURRENT_TIMESTAMP and
now() return the start time of the current transaction, would that be
the "plan" time? The timeofday() function returns the "wall clock" time
and advances during transactions. I think that this would be the
"execution" time.

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

Nov 23 '05 #9

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

Similar topics

0
by: AshifToday | last post by:
this was my and my frineds little project in earlier classes, the program seperates the composite and prime numbers in two sections of the screen ===================== /* This program has...
5
by: Paulovič Michal | last post by:
hi all, I have problem with SERIAL field type (or sequence functionality). I have table with three columns - ID, IDS, NAME. I want auto-increment IDS grouped by ID. Example: 1, 1, Ferdo 1, 2,...
0
by: Ivan Sergio Borgonovo | last post by:
I'd like to compute some "row like" results and return them from a function (and pass the result to PHP). Well I've read about composite type but all the references I've seen are about coding in...
0
by: Ivan Sergio Borgonovo | last post by:
what's wrong with this? create type tSession as ( ty_found boolean, ty_Session char(32) ); create or replace function GetSessionID( integer ) returns tSession as ' declare thisSession...
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...
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...
1
by: tsarevich | last post by:
create type my_type (my_test text, my_int integer); create function my_function(my_type) returns timestamp as 'begin return (current_timestamp); end; ' language 'plpgsql';
14
by: dave.dolan | last post by:
Basically I'd like to implement the composite design pattern with leaves that are either of reference or value types, but even using generics I can't seem to avoid boxing (using ArrayList or...
1
by: ma740988 | last post by:
Consider the source snippet. # include <iostream> struct foo_struct { int odx ; int pdx ; foo_struct () : odx ( 0 ) , pdx ( 0 )
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.