Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sql) support retrieving array values #17094

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Conversation

cirospaciari
Copy link
Member

@cirospaciari cirospaciari commented Feb 6, 2025

What does this PR do?

Fix: #16650
Support for:

  • bool_array = 1000
  • bytea_array = 1001
  • char_array = 1002
  • name_array = 1003
  • int8_array = 1016
  • int2_array = 1005
  • int2vector_array = 1006
  • int4_array = 1007
  • text_array = 1009
  • oid_array = 1028
  • tid_array = 1010
  • xid_array = 1011
  • cid_array = 1012
  • json_array = 199
  • xml_array = 143
  • point_array = 1017
  • lseg_array = 1018
  • path_array = 1019
  • box_array = 1020
  • polygon_array = 1027
  • line_array = 629
  • cidr_array = 651
  • float4_array = 1021
  • float8_array = 1022
  • circle_array = 719
  • macaddr8_array = 775
  • money_array = 791
  • macaddr_array = 1040
  • inet_array = 1041
  • aclitem_array = 1034
  • pg_database_array = 12052 | 10052
  • bpchar_array = 1014
  • varchar_array = 1015
  • date_array = 1182
  • time_array = 1183
  • timestamp_array = 1115
  • timestamptz_array = 1185
  • timetz_array = 1270
  • interval_array = 1187
  • bit_array = 1561
  • varbit_array = 1563
  • numeric_array = 1231
  • jsonb_array = 3807

Also added support for oid, tid, xid, cid and fix date types so dates are actually returned as Date objects

Key difference between Bun.sql and postgres.js is that we always return null when a value is null in an array, postgres.js may return "NULL" string or NaN, Invalid Date or null depending on the type and if is inside an array or not.

Example:

console.log(await sql`SELECT ARRAY[0, 1, 2, 3, 4, 5, NULL]::integer[]`);
// bun -> array: [ 0, 1, 2, 3, 4, 5, null ],
// postgres.js ->  array: [ 0, 1, 2, 3, 4, 5, NaN ],
console.log(await sql`SELECT ARRAY['Hello, World', 'Bun', '', 'NULL', NULL];`);
//bun -> array: [ "Hello, World", "Bun", "", "NULL", null ],
//postgres -> array: [ "Hello, World", "Bun", "", "NULL", "NULL" ],
  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

Tests

@robobun
Copy link

robobun commented Feb 6, 2025

Updated 9:40 PM PT - Feb 5th, 2025

@cirospaciari, your commit 6bdb098 is building: #11180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bun Postgres does not support array column type: ERR_POSTGRES_UNSUPPORTED_BYTEA_FORMAT
2 participants