473,811 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2280
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 | cf76cca2b562a0e ad48d3eb3810f51 cc
(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 | cf76cca2b562a0e ad48d3eb3810f51 cc
(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 | cf76cca2b562a0e ad48d3eb3810f51 cc
(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 | cf76cca2b562a0e ad48d3eb3810f51 cc
(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*******@sysc or.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
----------------------------------
154e80496745114 8bba5f28e044be8 28
(1 row)

and

test1=# select md5( random( ) );
md5
----------------------------------
31313f537b69d5f fe61be024a40b80 7e
(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*******@sysc or.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
----------------------------------
154e80496745114 8bba5f28e044be8 28
(1 row)

and

test1=# select md5( random( ) );
md5
----------------------------------
31313f537b69d5f fe61be024a40b80 7e
(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
----------------------------------
154e80496745114 8bba5f28e044be8 28
(1 row)

and

test1=# select md5( random( ) );
md5
----------------------------------
31313f537b69d5f fe61be024a40b80 7e
(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_TIMESTA MP 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
----------------------------------
154e80496745114 8bba5f28e044be8 28
(1 row)

and

test1=# select md5( random( ) );
md5
----------------------------------
31313f537b69d5f fe61be024a40b80 7e
(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_TIMESTA MP 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
2405
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 been made by A & A Group. Muhammad Ali: Roll # 1462 Class A-2 , B.Sc.(Hons.) in C.S.
5
5156
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, John 2, 1, Martin 1, 3, Elvira
0
350
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 C. That's not the way I'd like to follow by now. I was expecting to declare composite types in plpsql or plain sql in a similar way I'd do in C/C++ with struct/class. I've found this
0
374
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 tSession; begin
0
1483
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 message file plpgsql not found in lib directory.
1
2214
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 within nested loops. No problem. begintest2() simplifies this, omitting the nested loops. Still no problem.
1
1704
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
5042
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 Object) Is this even possible, or is the composite pattern doomed to use the System.Object type forever? I have tried using interfaces with generics, but I always stumble on the Value property (when trying to return the value of a particular node)
1
2109
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
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10389
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.