pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
table value function help
4+ messages / 3 participants
[nested] [flat]

* table value function help
@ 2018-11-22 16:25 Glenn Schultz <glenn@bondlab.io>
  2018-11-22 16:44 ` Re: table value function help Adrian Klaver <adrian.klaver@aklaver.com>
  2018-11-22 17:02 ` Re: table value function help David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Glenn Schultz @ 2018-11-22 16:25 UTC (permalink / raw)
  To: pgsql-general

Hello,

I have a table value function and would like the first and second input to
take multiple arguments (array or list) I suppose.  Like the below:


create or replace function myfunction(sector, agency, term)
returns table (cusip char(9), sector char(12))
language sql
stable
as $function$

select foo
from
atable
where
sector in (myfunction.sector)

usage

sectorselect('sector_1 sector_2', 'agent_1 agent_2, 120)

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: table value function help
  2018-11-22 16:25 table value function help Glenn Schultz <glenn@bondlab.io>
@ 2018-11-22 16:44 ` Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Adrian Klaver @ 2018-11-22 16:44 UTC (permalink / raw)
  To: Glenn Schultz <glenn@bondlab.io>; pgsql-general

On 11/22/18 8:25 AM, Glenn Schultz wrote:
> Hello,
> 
> I have a table value function and would like the first and second input 
> to take multiple arguments (array or list) I suppose.  Like the below:

I cannot follow what you are trying to achieve.

> 
> 
> create or replace function myfunction(sector, agency, term)
> returns table (cusip char(9), sector char(12))
> language sql
> stable
> as $function$
> 
> select foo
> from
> atable
> where
> sector in (myfunction.sector)

 From above:

1) Where is term used?

2) Where is agency used?

3) If you are returning two fields why is there only one in the query?

It might be best to outline the procedure you want to execute. As example:

1) Consume inputs of this type and layout.

2) Process inputs this way.

3) Output this.



> 
> usage
> 
> sectorselect('sector_1 sector_2', 'agent_1 agent_2, 120)

I going to assume sectorselect = myfunction, correct?
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: table value function help
  2018-11-22 16:25 table value function help Glenn Schultz <glenn@bondlab.io>
@ 2018-11-22 17:02 ` David G. Johnston <david.g.johnston@gmail.com>
  2018-11-22 18:43   ` Re: table value function help Glenn Schultz <glenn@bondlab.io>
  1 sibling, 1 reply; 4+ messages in thread

From: David G. Johnston @ 2018-11-22 17:02 UTC (permalink / raw)
  To: Glenn Schultz <glenn@bondlab.io>; +Cc: pgsql-general

On Thursday, November 22, 2018, Glenn Schultz <glenn@bondlab.io> wrote:

> Hello,
>
> I have a table value function and would like the first and second input to
> take multiple arguments (array or list) I suppose.  Like the below:
> create or replace function myfunction(sector, agency, term)
>

Create function myfunction(arg1 text[], arg2 text[]) ...

David J.

p.s. You should avoid using the “char” data type in PostgreSQL, use text or
varcar instead.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: table value function help
  2018-11-22 16:25 table value function help Glenn Schultz <glenn@bondlab.io>
  2018-11-22 17:02 ` Re: table value function help David G. Johnston <david.g.johnston@gmail.com>
@ 2018-11-22 18:43   ` Glenn Schultz <glenn@bondlab.io>
  0 siblings, 0 replies; 4+ messages in thread

From: Glenn Schultz @ 2018-11-22 18:43 UTC (permalink / raw)
  To: david.g.johnston@gmail.com; +Cc: pgsql-general

Thanks!

I googled this for 3-days before coming here.  I see what you mean.  Thank
you so much will make the recommended changes.

Glenn

On Thu, Nov 22, 2018 at 11:02 AM David G. Johnston <
david.g.johnston@gmail.com> wrote:

> On Thursday, November 22, 2018, Glenn Schultz <glenn@bondlab.io> wrote:
>
>> Hello,
>>
>> I have a table value function and would like the first and second input
>> to take multiple arguments (array or list) I suppose.  Like the below:
>> create or replace function myfunction(sector, agency, term)
>>
>
> Create function myfunction(arg1 text[], arg2 text[]) ...
>
> David J.
>
> p.s. You should avoid using the “char” data type in PostgreSQL, use text
> or varcar instead.
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-11-22 18:43 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-22 16:25 table value function help Glenn Schultz <glenn@bondlab.io>
2018-11-22 16:44 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-11-22 17:02 ` David G. Johnston <david.g.johnston@gmail.com>
2018-11-22 18:43   ` Glenn Schultz <glenn@bondlab.io>

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