pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ian Morgan <imorgan@webcon.net>
To: pgsql-sql@postgresql.org
Subject: SELECT in a function != SELECT ?
Date: Thu, 25 Apr 2002 01:44:15 -0400 (EDT)
Message-ID: <Pine.LNX.4.44.0204250101300.26231-100000@light.webcon.net> (raw)
In-Reply-To: <200204250441.AAA23640@io.hypernet.com.py>

While trying to formulate an answer to another user's query on this list, I
came a across what I think is strange behaviour in an SQL funsction:

The 3rd column of my 'contacts' table is 'first_name'.

A regular select will allow me to find this:

SELECT a.attname FROM pg_class c, pg_attribute a
        WHERE c.relname = 'contacts'
        and a.attnum = 3 and a.attrelid=c.oid;

  attname
------------
 first_name
(1 row)


But when turned into a function:

CREATE FUNCTION get_colname (name,smallint)
RETURNS name AS '
        SELECT a.attname FROM pg_class c, pg_attribute a
        WHERE c.relname = ''$1''
        and a.attnum = $2 and a.attrelid=c.oid
'
LANGUAGE SQL;

SELECT get_colname('contacts',3);

 get_colname
-------------

(1 row)


The result is empty!?

Even more strange:

SELECT 'x'||get_colname('contacts',3)||'x' as foo;

 foo
-----

(1 row)

Should I not be seeing "xx" as the result here!? What's going on? Anyone
wknow why the above function get_colname isn't doing what I expect?

Regards,
Ian Morgan
-- 
-------------------------------------------------------------------
 Ian E. Morgan        Vice President & C.O.O.         Webcon, Inc.
 imorgan@webcon.net         PGP: #2DA40D07          www.webcon.net
    *  Customized Linux network solutions for your business  *
-------------------------------------------------------------------




view thread (4+ messages)  latest in thread

Message-ID: <Pine.LNX.4.44.0204250101300.26231-100000@light.webcon.net>
Permalink:  ../Pine.LNX.4.44.0204250101300.26231-100000@light.webcon.net/
Also on:    postgresql.org/message-id/Pine.LNX.4.44.0204250101300.26231-100000@light.webcon.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: imorgan@webcon.net
  Subject: Re: SELECT in a function != SELECT ?
  In-Reply-To: <Pine.LNX.4.44.0204250101300.26231-100000@light.webcon.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox