pg.ddx.io pgsql-general@postgresql.org mailing list archivehelp / color / mirror / Atom feed
trouble writing plpgsql 2+ messages / 2 participants [nested] [flat]
* trouble writing plpgsql @ 2022-12-22 11:37 hamann.w@t-online.de 0 siblings, 1 reply; 2+ messages in thread From: hamann.w@t-online.de @ 2022-12-22 11:37 UTC (permalink / raw) To: pgsql-general@lists.postgresql.org Hi, 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) 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? Wolfgang Hamann ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: trouble writing plpgsql @ 2022-12-22 11:43 hubert depesz lubaczewski <depesz@depesz.com> parent: hamann.w@t-online.de 0 siblings, 0 replies; 2+ messages in thread From: hubert depesz lubaczewski @ 2022-12-22 11:43 UTC (permalink / raw) To: hamann.w@t-online.de; +Cc: pgsql-general@lists.postgresql.org On Thu, Dec 22, 2022 at 11:37:22AM -0000, hamann.w@t-online.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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2022-12-22 11:43 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2022-12-22 11:37 trouble writing plpgsql hamann.w@t-online.de 2022-12-22 11:43 ` hubert depesz lubaczewski <depesz@depesz.com>
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