[SQL] varchar value comparisons not working?

2009-04-24 Thread Shawn Tayler
Hello,

I'm doing a quick comparison between a couple tables, trying to cleanup
some inconsistencies, and what should be a simple check between 2 tables
doesn't seem to be working.  psql is 8.3.7 and server is 8.2.13.

I run the following:

select sfd.lid as sflid,sd.lid as slid,sfd.serial from sfd,shawns_data
sd where sfd.serial = sd.serial_number order by sfd.lid; 

the lid columns in both tables should be identical, but as you see in
this sample, they do differ:

 sflid | slid  |  serial  
---+---+--
 14056 | 14056 | 9614583
 14057 |   | 9614984
 14058 | 14058 | 9614737
 14059 | 14059 | 9614579
 14060 |   | 9614827
 14061 | 14061 | 9614726
 14062 | 14062 | 9614966
 14063 | 14063 | 9615079

So running this query:

select count(*) from sfd,shawns_data sd where sfd.serial = sd.serial_number and 
sfd.lid != sd.lid; 

I should show some rows that do not match, at least 2 (there are more than 
shown).  

But instead I get this:

 count 
---
 0
(1 row)


What am I doing wrong?


-- 
Sincerely,

Shawn Tayler
Radio Network Administrator
Washoe County Regional Communications System
Telecommunications Division
Technology Services Department
County of Washoe
State of Nevada
Ofc  (775)858-5952
Cell (775)771-4241
FAX  (775)858-5960


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] varchar value comparisons not working?

2009-04-24 Thread Tom Lane
Shawn Tayler  writes:
> I run the following:

> select sfd.lid as sflid,sd.lid as slid,sfd.serial from sfd,shawns_data
> sd where sfd.serial = sd.serial_number order by sfd.lid; 

> the lid columns in both tables should be identical, but as you see in
> this sample, they do differ:

>  sflid | slid  |  serial  
> ---+---+--
>  14056 | 14056 | 9614583
>  14057 |   | 9614984
>  14058 | 14058 | 9614737
>  14059 | 14059 | 9614579
>  14060 |   | 9614827
>  14061 | 14061 | 9614726
>  14062 | 14062 | 9614966
>  14063 | 14063 | 9615079

> So running this query:

> select count(*) from sfd,shawns_data sd where sfd.serial = sd.serial_number 
> and sfd.lid != sd.lid; 

> I should show some rows that do not match, at least 2 (there are more than 
> shown).  

> But instead I get this:

>  count 
> ---
>  0
> (1 row)

Probably those "blank" values of slid are really NULLs.  A NULL isn't
"equal to" something else, but it isn't "unequal" either.  You could
use IS DISTINCT FROM instead of != in your second query.

regards, tom lane

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] Variable number or arguments to a function possible?

2009-04-24 Thread Chris Ruprecht

Hello everybody,

Is it possible to create a function that can take a variable number of  
arguments?
I would like to write a function that creates a new record in the  
database. Based on what I send it, it should create a record in the  
appropriate table.


Simple pseudo-code example:

... function create_record( varchar [,...] ) returns bigint as

if $1 = 'state' then insert into state ( $2, $3 ) // $2 being state  
name, and $3 state code
if $1 = 'phone' then insert into phone ( $4::bigint, $2, $3 ) // $2 =  
phone number, $3 = phone type, $4 = id of person that ownes the phone


and so on.

How would I declare that function?

Thanks.


best regards,
chris
--
chris ruprecht
database grunt and bit pusher extraordinaíre


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Variable number or arguments to a function possible?

2009-04-24 Thread Milen A. Radev
Chris Ruprecht написа:
> Hello everybody,
> 
> Is it possible to create a function that can take a variable number of
> arguments?
> I would like to write a function that creates a new record in the
> database. Based on what I send it, it should create a record in the
> appropriate table.
> 
> Simple pseudo-code example:
> 
> ... function create_record( varchar [,...] ) returns bigint as
> 
> if $1 = 'state' then insert into state ( $2, $3 ) // $2 being state
> name, and $3 state code
> if $1 = 'phone' then insert into phone ( $4::bigint, $2, $3 ) // $2 =
> phone number, $3 = phone type, $4 = id of person that ownes the phone
> 
> and so on.
> 
> How would I declare that function?

You'll be able to do that (or something similar) in the next, still
in beta, version 8.4
(http://www.postgresql.org/docs/8.4/static/xfunc-sql.html#XFUNC-SQL-VARIADIC-FUNCTIONS),
but right now the closest to what you want is function overloading
(http://www.postgresql.org/docs/current/static/xfunc-overload.html).



-- 
Milen A. Radev


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Variable number or arguments to a function possible?

2009-04-24 Thread Tom Lane
Chris Ruprecht  writes:
> Is it possible to create a function that can take a variable number of  
> arguments?

No, but you can make it take an array and then write something like

myfunc(array[x, y, ...])

8.4 will have some syntactic sugar that looks like variable numbers of
arguments, but it's reducing to the above underneath.

regards, tom lane

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql