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

Support for PostgreSQL own custom types? #301

Open
C-Duv opened this issue Jun 8, 2023 · 0 comments
Open

Support for PostgreSQL own custom types? #301

C-Duv opened this issue Jun 8, 2023 · 0 comments

Comments

@C-Duv
Copy link

C-Duv commented Jun 8, 2023

Hello,

It seems the library does not support PostgreSQL custom types.

Say I have the following physical_address type:

CREATE TYPE physical_address AS (
    name text,
    extra_recipient_information text DEFAULT NULL,
    street_number_and_name text,
    extra_street_information text DEFAULT NULL,
    post_office_box text,
    postal_code text,
    locality text,
    country text
);

And a table of clients:

CREATE TABLE IF NOT EXISTS clients (
    id uuid NOT NULL DEFAULT gen_random_uuid(),
    name text NOT NULL,
    address physical_address NOT NULL
);

Containing the following row:

id|name   |address                                         |
--+-------+------------------------------------------------+
… |Foo Bar|(Some Name,42th street,BP123,75001,Paris,France)|

With the following code:

$connection = new Nette\Database\Connection(…);
$some_client = $connection->fetch(
    'SELECT * FROM "clients" LIMIT 1',
)->fetch();

var_dump($some_client->address) . PHP_EOL;

It looks like address is seen as a simple string:

string(48) "(Some Name,42th street,BP123,75001,Paris,France)"

Is there a way to access sub fields? Something like:

$some_client->address->locality;
$some_client->address['locality'];
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

No branches or pull requests

1 participant