473,799 Members | 3,005 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 2279
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
2404
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
1481
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
5040
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
2107
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
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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
10268
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
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7571
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
5467
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
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.