Importing .csv with timestamp column (dd.mm.yyyy hh.mm.ss) using psql \copy

Have you tried setting the datestyle setting of the server? SET datestyle=”ISO,DMY”; You are using the psql meta-command \copy, which means the input file is local to the client. But it’s still the server who has to coerce the input to matching data-types. More generally, unlike the psql meta-command \copy which invokes COPY on the … Read more

PostgreSQL – set a default cell value according to another cell value

This is not possible with a simple DEFAULT value, as the manual clearly states: The value is any variable-free expression (subqueries and cross-references to other columns in the current table are not allowed). You could use a trigger instead: CREATE OR REPLACE FUNCTION trg_foo_b_default() RETURNS trigger LANGUAGE plpgsql AS $func$ BEGIN — For just a … Read more

Size limit of JSON data type in PostgreSQL

Looking at the source for PostgreSQL 9.2.1: Source: postgresql-9.2.1\src\backend\utils\adt\json.c: /* * Input. */ Datum json_in(PG_FUNCTION_ARGS) { char *text = PG_GETARG_CSTRING(0); json_validate_cstring(text); /* Internal representation is the same as text, for now */ PG_RETURN_TEXT_P(cstring_to_text(text)); } Update for PostgreSQL 9.3.5: The code has changed in the json_in function, but the json internal representation is still text: Source: … Read more

Return SETOF rows from PostgreSQL function

Sanitize function What you currently have can be simplified / sanitized to: CREATE OR REPLACE FUNCTION func_a (username text=””, databaseobject text=””) RETURNS ???? LANGUAGE plpgsql AS $func$ BEGIN RETURN QUERY EXECUTE format (‘SELECT * FROM %s v1 LEFT JOIN %I v2 USING (id)’ , CASE WHEN username=”*” THEN ‘view1’ ELSE ‘view3’ END , databaseobject); END … Read more