pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Passing enum Parameters to User-defined C-Language Functions
2+ messages / 2 participants
[nested] [flat]

* Passing enum Parameters to User-defined C-Language Functions
@ 2023-10-23 16:54  Albrecht Dreß <albrecht.dress@posteo.de>
  0 siblings, 1 reply; 2+ messages in thread

From: Albrecht Dreß @ 2023-10-23 16:54 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi,

I have a (I hope not too dumb) question regarding the use of enum parameters in a user-defined function written in C, e.g. for the example given in [1]: CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');

- How would a “mood” parameter be encoded when it is passed to the function?  “Four bytes on disk” might imply that its either an int4 or a float4?
- How is the association between enumlabel (e.g. 'happy') and value?  The same as enumsortorder in pg_enum?
- How are NULL values encoded?

Or is it a bad idea to use an enum in this case – actually, an int2 plus a few #define's would do the job, too, but the dedicated type looks cleaner to me.

Thanks in advance,
Albrecht.


[1] <https://www.postgresql.org/docs/16/datatype-enum.html;

Attachments:

  openpgp-digital-signature.asc (application/pgp-signature, 487B) download

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

* Re: Passing enum Parameters to User-defined C-Language Functions
@ 2023-10-23 17:08  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Albrecht Dreß <albrecht.dress@posteo.de>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2023-10-23 17:08 UTC (permalink / raw)
  To: Albrecht Dreß <albrecht.dress@posteo.de>; +Cc: pgsql-general@lists.postgresql.org

Albrecht =?iso-8859-1?b?RHJl3w==?= <albrecht.dress@posteo.de> writes:
> - How would a “mood” parameter be encoded when it is passed to the function?

It's an OID, which you'd have to look up in the pg_enum catalog if
you want to know the string representation.

			regards, tom lane





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


end of thread, other threads:[~2023-10-23 17:08 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23 16:54 Passing enum Parameters to User-defined C-Language Functions Albrecht Dreß <albrecht.dress@posteo.de>
2023-10-23 17:08 ` Tom Lane <tgl@sss.pgh.pa.us>

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