Re: trouble writing plpgsql

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: hamann(dot)w(at)t-online(dot)de
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: trouble writing plpgsql
Date: 2022-12-22 11:43:30
Message-ID: Y6RC4lRud32pEcPF@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 22, 2022 at 11:37:22AM -0000, hamann(dot)w(at)t-online(dot)de wrote:
> I want to make a function to parsetext and return key-value pairs
> create or replace function extractinfo (text) returns table (key char[1], val text)

Please don't use char datatype:
https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_char.28n.29

> language plpgsql as $$
>
> I first tried
> declare
> xx record;
> begin
> ....
> xx.key = ....; xx.val = ....;
> return next xx:
> This is not possible because xx needs to know its structure before the fields can be assiged to.
> Could I declare xx as having these fields in the first place, do Ineedto create a type for key, val
> first?

select '...' as key, '...' as val into record;

depesz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Gilman 2022-12-22 12:50:57 Re: Implementing foreign data wrappers and avoiding n+1 querying
Previous Message hamann.w 2022-12-22 11:37:22 trouble writing plpgsql