October 26, 2024
Chicago 12, Melborne City, USA
SQL

Select a value from a table using table column key


I have the following Postures table:

CREATE TABLE users
(
    id bigint NOT NULL,
    created_by character varying(255) COLLATE pg_catalog."default",
    creation_date timestamp(6) without time zone,
    default_travel_method_id character varying(255) COLLATE pg_catalog."default",
    default_shipping_address_id character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT users_pkey PRIMARY KEY (id)
)

When I use this select to select also a column from another table I use this in Oracle:

    SELECT
    created_by,
    (select reference from methods where id = default_travel_method_id) as default_travel_id,
    (select reference from addresses where id = default_shipping_address_id) as defaultShippingAddressId,
    from users;

But in Postures I get this error:

ERROR:  operator does not exist: bigint = character varying
LINE 8: ...reference from methods where id = default_...
                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts. 

Do you know in Postgres what is the proper way to use a column expression to select a value from another table?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video